Sending player positions through the Server

Hello everyone,

  I'm relatively new to Java networking, but very familiar with Java in general.  I'm trying to make a simple networked game (4-5 players max, just me and a few friends) where each player needs to know the positions of the other players so they can draw their characters at the appropriate coordinate. I'm not sure what the best logic behind this would be?  I was thinking the Client sends its position to the server, and then the server sends this position (along with the others) to each client.  What would be a general approach to implement this, or a better strategy?

Thanks in advance!

At such a small scale, the design hardly matters. Simply create a Client-like class that handles all the Socket IO. Put the clients in the vector on the Server, and whenever you need to broadcast something, send the message to all clients in that vector.

You have to create your own protocol for delimiting the packets, like prepending a packet with the packet-length, or using null-terminating bytes when you’re only sending text around.

for such simple example, it’s enough that you set up server to send data to clients every X seconds, and clients do the same just sending to server their data. Generally it shouldn’t when clients send their messages and server sends theirs, as long as messages are being sent in regular intervals. By this I mean it doesn’t matter if server sends 0.1 seconds after he gets messages from client and such.
I just created sending thread that was doing .wait(X) and sending all queued data to all clients… this way if you need to send an instant message you can always put that instant message to sending queue and wake up the thread… it’s best when you figure it out by yourself.