Jump to content
  • Advertisement
Sign in to follow this  
MrProper

Communication between clients

This topic is 2764 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

I am programming simple MP game in java, but I am little confused about multiplayer part. Problem is, I cant find a way to make clients connected to server communicate with each other.

I am creating new thread for each connection, but still I fail to see how to send information from client1 to server and from server to client2. I know there must be some simple solution, but it just seems missing me.

Share this post


Link to post
Share on other sites
Advertisement
ok, so i have managed to create something, its working, but i am not completly sure about it...

Im giving to every connection object, where are stored references for its
output stream and also output stream of other player. Is it good idea? Are there any possible drawbacks of this solution?

Share this post


Link to post
Share on other sites
Generally in most cases each client will provide updates about it's local objects player position, chat input etc. The server then compiles all the inputs from each of the clients into one frame update. This is then sent on to all the clients whereupon they update their versions of the objects with the servers data.

Connections between clients are generally not used in the standard client-server structure but are used in peer to peer structures.

Share this post


Link to post
Share on other sites
To illustrate Darg's point, your server likely has a number of classes that are handling various aspects of the game server's logic.

Connection Handler:

public void handleMovementPacket(WorldPacket packet) {
gridManager.movePlayer(getClientConnection(), packet);
}

Essentially the above illustrates that the connection handler has a method specifically for movement packets. When the packet is determined to be a movement type, this method is called and it invokes the grid manager to manipulate the player's location.

Grid Manager

public void movePlayer(ClientConnection client, WorldPacket packet) {
GridPosition pos = getPosition(client);
if(packet.getType().equals(MOVE_FORWARD)) {
pos.x += FORWARD_STEP_VALUE;
updatePosition(client, pos);
ClientConnection[] clients = getNearbyClients(pos);
SendUpdateToClients(packet, clients);
}
}
public void SendUpdateToClients(WorldPacket packet, ClientConnection[] c) {
for(ClientConnection client : c) {
SendUpdateToClient(packet, c);
}
}
public void SendUpdateToClient(WorldPacket packet, ClientConnection c) {
// either queue or directly send
c.sendPacket(packet);
}

hope this helps

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!