954,525 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Send UPD Packet in C#

Hello everybody!
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!

galaris
Newbie Poster
1 post since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

I'm assuming you mean "UDP".

byte[] data = new byte[1024];
string sData = "<the packet data - fill with what you want>";
IPEndPoint ep = new IPEndPoint("127.0.0.1", 8000); // change to the IP address and port of your server

Socket gameServer = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
data = Encoding.ASCII.GetBytes(sData);
gameServer.SendTo(data, data.Length, SocketFlags.None, ep);


Of course, there are all sorts of things that can go wrong - you need to put in exception handling to make sure you catch any issues.

Now, if your data is not string data and is already binary, well, you can just serialize the data into the byte array and send it along.

mcriscolo
Posting Whiz in Training
218 posts since Apr 2008
Reputation Points: 57
Solved Threads: 64
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: