Networked Java Game Protocol Speci Cation
Networked Java Game Protocol Speci Cation
Upon startup, necessary status information is exchanged via TCP before the
start of the game. The TCP connection is closed when the setup is complete
and the UDP sockets for the exchange of game state are opened on both sides.
1 TCP Prologue
Server continuously listens on TCP port 10250 for new clients (multi-threaded).
• Client: “protocol: SpaceShooter client version 1.0”
• Server: “protocol: SpaceShooter server version 1.0”
• Client: “player: [player name]”
• Server: “player: name ok, ID [i], field size [x] [y]” or “player: name in use”
if it’s already taken. [i] is an identifier for the player, and [x] and [y] are
the size of the game field.
• Client: “port: [client UDP port]”
• Server: “port: [server UDP port]”
All strings should terminate with a newline character. The player ID is
an integer value. It is chosen by the server and should be different for each
client (i.e., start with random ID and increment by one for each new client).
The TCP connection is closed after this exchanges. As always, check that the
correct messages are exchanged and print error messages if not (e.g. wrong
protocol version, ...).
Server and client then open UDP sockets on the specified ports and start
sending updates.
1
the spaceships) in a single packet every 50ms. This update interval should be
configurable for client as well as server.
Both client and server packets have a sequence number to detect packet loss
(note: they are independent; this is not used as an ACK). The sequence number
is increased by one for each consecutive message.
2 byte values are always first high-byte, then low-byte (network order; default
order in Java).
2
• shot time of 1st player (1 byte)
• status of 1st player (1 byte)
• score of 1st player (1 byte)