Im am currently writing some test code for a multiplayer snake game. (achtung die kurve - clone).
I am using TCP Sockets atm.Current situation:
new game round:
I send a short array from the server to the clients with their initial random x and y positions. > 2 short per player
I send left/right pressed/released byte from clients to server. Every 30ms, the server updates the player positions, and sends the x and y offset of each player to its previous position. in a byte array. > 1 byte per player
I am using socket.setTcpNoDelay(true); so +/- 33 tcp packets are sent each second, holding a byte array of maximum length 6. (max 6 players).
But I read in TCP vs UDP that the TCP overhead is 40bytes?
(40+6)*33 = 1.5 kb/sec sent to each player makes 9kb/sec upload bandwith on the server?
Those 9kb only hold around 1.2kb of data.
How should I reduce the overhead?
Will UDP help? Or do a need to change the way I communicate between client and server.
If I send the player movement keys to all the clients, and let them calculate the new positions every 30 ms, it will be much better ofcourse. But then the server and each individual client won't be synchronized.
The code is available for download here:http://kurve.knot.be/kurvetest.zip