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,
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.
There are few properties I need to send to the server; X location, Y location, how the unit is rotated (Angle), Health.
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.
Also, so I simply write this information to the dataoutputstream for each gameloop?
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.