コード例 #1
0
        public void SendPacket(string msg, byte ttl, byte label)
        {
            List <byte> labels = new List <byte>();

            labels.Add(label);
            if (clientSocket.Connected)
            {
                MPLSPacket packet = new MPLSPacket(msg, ttl, labels, name);
                Console.WriteLine(packet.MPLSInfo());
                try
                {
                    ReturnLog("Trying to send the message...");
                    Send(clientSocket, packet.GetBytes());
                    Thread.Sleep(1000);
                    if (response.Equals("OK"))
                    {
                        ReturnLog("Message was sent");
                    }
                    else
                    {
                        ReturnLog("Failed to send the message");
                    }
                    response = String.Empty;
                }
                catch (Exception)
                {
                    ReturnLog("Failed to send the message");
                }
            }
        }
コード例 #2
0
        public void ReceivePacket()
        {
            //sprawdzac czy sa dane do odebrania
            while (true)
            {
                if (clientSocket.Connected)
                {
                    byte[] buffer  = new byte[256];
                    var    message = Encoding.Default.GetString(buffer, 0, clientSocket.Receive(buffer));
                    if (message != null && message.Length > 5)
                    {
                        byte[] buffer2 = Encoding.Default.GetBytes(message);

                        MPLSPacket packet = new MPLSPacket(buffer2);
                        ReturnLog("Message received: " + packet.Message + " from " + packet.Source);
                    }
                    else
                    if (message != null)
                    {
                        response = message;
                    }
                }
            }
        }