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); } }
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; } } }
public static void SendTCP(NetworkStream s, WiRCMessage msg) { var buf = msg.Serialize(); s.Write(buf, 0, buf.Length); }