hlim
hlim

Reputation: 945

Design and logic for client/server networking games

I am creating a simple android game that deals with multiplayer and connecting to server. This is what I want to achieve for my game.

Client sends keystroke movement to server.

Server accepts input, update the state and calculates and returns new position to client

Client gets new position and update the screen.

I already have some code written and so my one of my threads sends keystroke to server, waits for the new position, then update the screen. The thing is there is lag between the player's movement. I think it has to do with latency. I also tried two thread, one for sending/receiving data from server and another is updating the screen. But it didnt' solve my latency problem.

Can anyone suggest a good design for networking game?

Do I need to do early prediction?

Do I need separate thread for fetching data and rendering screen?

P.S.This is my first time creating a network game so i have no idea what im doing.

Upvotes: 1

Views: 655

Answers (1)

Alle
Alle

Reputation: 324

The structure I prefer to use is to have one thread updating graphics and logic on the client side, and then one thread receiving and sending data to the server. If you have problems with latency, there is a magic option which might solve it if you want data to be sent continously. (at least this is the syntax if you are using java)

mySocket.setTcpNoDelay(true);

This option solved my latency issues when I sent real-time coordinates over a network.

Edit: I think TCP by default waits and bunches together data before sending it, which could be a problem if you want to send small updates fast.

Upvotes: 0

Related Questions