Sending UDP Packet in C#

DOminik picture DOminik · Apr 14, 2010 · Viewed 66.4k times · Source

I have a game server (WoW). I want my players to download my custom patches to the game. I've done a program that checks for update/downloading things. I want my program to send a packet to my game server if player have all my patches. I dont need any response from the server, it will handle it, but its another story.

So I want to know, how to send a packet to a server.

Thank you!

Answer

nos picture nos · Apr 14, 2010
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,
ProtocolType.Udp);

IPAddress serverAddr = IPAddress.Parse("192.168.2.255");

IPEndPoint endPoint = new IPEndPoint(serverAddr, 11000);

string text = "Hello";
byte[] send_buffer = Encoding.ASCII.GetBytes(text );

sock.SendTo(send_buffer , endPoint);