Networking protocol

Hi.

I’m looking for a good synchronising method for my MMORPG game, I’m using an Client/Server architecture.
Actually, I don’t know how to design my network protocol: how to prevent lags and other timing problems…
What is the best way to synchronize the clients with the server?
If you have any idea, could you describe your solution?

Thanks.

I have similar questions.

Although my game is not MMORPG, it’s a simple fighter game.

I’ve managed to get simple communications to work, like client sends X-axis coordinate to server, and server echos back those same coordinates.

Forgive me about these stupid questions, but:

For DataOutputStream there is the method, writeInt(int). How do I send X and Y coordinates, and make the server tell the difference? It seems I can only send primitives over, so I need a way for the server to determine what is what. Would I send over a String in some predetermined format? Like: “324,134” to indicate x,y point?

There are few properties I need to send to the server; X location, Y location, how the unit is rotated (Angle), Health.

Also, so I simply write this information to the dataoutputstream for each gameloop?

edit: sorry for the hijack :slight_smile: topics look similar, and didn’t want repost this question.

While you COULD use ObjectOutputStream and serialization, that in general is the wrong solution.
The right one is just be the order of the data. if you write X follwoed byY then you are going to read X followed by Y.

Okay take a BIIG step back. And for the moment forget about DataOutputStream.

Network data is generally sent in packets. Each packet is clump of bytes in a known organization that you decide when you design the network code. In the case of a stream protocol like TCP, you “packetize” by writing a header at the front of each packet, this can be as little as a single int telling you the size of the following packet in bytes. You want to write the packet with a single call to OutputStream.write. This way it willa rrive together as a sensible packet on the opther end.

This means you want to have your entire packet in a byte array to write(). You do this by wapping a DataOutputStream around a ByteArrayOutputStream. Write your data in sequence to the DataOutputStream, flush() the stream (critically important) and then get the byte array from the ByteArrayOutputStream.

You send that byte array with a write() call on the outputstream returned from your socket;'s getOutputStream() call.
On the other side you read the size as a byte from the inputstream returned from that socket’s getInputStream() call, youi then create a byte array big enough to gold the packet and read that from the dtream. That is then generally passed to your higher level logic which will pull it apart by wrapping a ByteArrayInputStream around the byte array and a DataInputStream around thet ByteArrayInputStream. Then you read the data from that stream in exactly the order you wrote it when sending it.

Well unless youir game is trivially simplke there is nothing “simple” about this. It wil lalways depend on how your game is structured, but usually writing a apcket per frame will send way more data then you want to spend your time either sending or receiving. Networkign isn’t sometying you can easily “paste onto” a game at the end. To be done well it needs to be consdiered as part of your total game design. If youa re going to be trying to do game play over the inetrnet this ebcoems even more critical as handling network latencies well is going to have to drive the entire design of your game.

A good example of how networking effects the core of your game design can be foudn in this discussion we had with Kev about his neotworking in his RPG. There is a lot of good stuff to be elarned sifiting through this…

http://www.java-gaming.org/forums/index.php?topic=10516.0

Seems like I have some nice amount of reading and training to do … better get to it.

Thanks for your reply Jeff, was useful.

Consider HeadQuarters ‘location’ subsystem which give you automatic distribution of positional data. Plus some dead-reckoning if you like. The protocol is binary and saves some bandwidth compared to string serialized transmission.

http://www.flyingguns.com

Browse to the SourceForge project and grab the code from cvs.