Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static Int32 port = 11000;
- private static UdpClient udpClient = new UdpClient(port);
- public static void receive_threaded()
- {
- Thread t = new Thread(() =>
- {
- while (true)
- {
- IPEndPoint remoteIPEndPoint = new IPEndPoint(IPAddress.Any, port);
- byte[] content = udpClient.Receive(ref remoteIPEndPoint);
- if (content.Length > 0)
- {
- string message = Encoding.UTF8.GetString(content);
- if (action_message_receive != null) action_message_receive(String.Format("Recv({0}): {1}", remoteIPEndPoint.Port, message));
- parseMessage(message);
- }
- }
- });
- t.Start();
- }
- private static void send_message(string ip, string message)
- {
- byte[] packetData = System.Text.UTF8Encoding.UTF8.GetBytes(message);
- int port = 11000;
- IPEndPoint ep = new IPEndPoint(IPAddress.Parse(ip), port);
- Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
- client.SendTo(packetData, ep);
- if (action_message_send != null) action_message_send("Send: " + message);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement