Class sending

I have a class Unit. It’s contains other classes i written, for example BasicClass.
When the battle begins - first and second players sends 5 Units to server, and server sends player2’s units to player1 and player1’s units to player2

Can i send a Unit to server?
And is there a java turn based game networking tutorials? I have troubles with this kind of games.

Yes, by making it implement java.io.Serializable and then using ObjectOutputStream and ObjectInputStream.

Have a look at Kryonet! It’s NIO networking, sending serialized objects. :slight_smile:

if you have to send many information in small time, it is better implement externalizable and implement your own algorithm.
for example instead of boolean (1 byte) you can use byte, that give you all 255 possible states, and the “sqeeze” many status in one byte.
Also it is a good idea to use java.nio, you loose the nice-looking Seirialize and Externalize, but you get SO asynchronism.
But this is a good option (because of implementation and testing time) only for real-time game