示例#1
0
 public static void SendUdp(WiRCMessage msg, IPAddress destIp, ushort destPort, ushort localPort)
 {
     using (UdpClient udpClient = new UdpClient(localPort))
     {
         udpClient.Connect(destIp, destPort);
         var data = msg.Serialize();
         udpClient.Send(data, data.Length);
     }
 }
示例#2
0
        private void StartTCPListener()
        {
            Thread.Sleep(50);
            var buf = new byte[1024];

            while (!disposed)
            {
                var bytes = TcpStream.Read(buf, 0, buf.Length);
                if (bytes == 0)
                {
                    Thread.Sleep(50);
                    continue;
                }

                var msg = new WiRCMessage(buf);
                Console.WriteLine(msg.Cmd + " " + msg.Length + " of " + bytes);
                switch (msg.Cmd)
                {
                case WiRCCmd.WST:
                    SenderId = msg.Data[0];
                    Console.WriteLine("Sender " + SenderId);
                    CamsNumber = msg.Data[1];
                    PCDPort    = (ushort)((msg.Data[2] << 8) + msg.Data[3]);
                    break;

                case WiRCCmd.AGR:
                    Console.WriteLine("AGR " + msg.Data[66]);
                    if (msg.Data[66] == 0)
                    {
                        InControl = true;
                    }
                    break;

                default:
                    Console.Write(BitConverter.ToString(msg.Data));
                    break;
                }
            }
        }
示例#3
0
        public static void SendTCP(NetworkStream s, WiRCMessage msg)
        {
            var buf = msg.Serialize();

            s.Write(buf, 0, buf.Length);
        }