• Post Reply Bookmark Topic Watch Topic
  • New Topic

Persistent or non-persistent connection?

 
Jón Jónsson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I'm writing a simple game where clients connect to the server and can see each other on a small board moving around. The server is running on my local machine and my friend that lives in another town connects to the server via my public ip address. I works but my friends movement is very choppy f.ex if he hits a button to move to right a several times in a short period his movement is seen by him and myself as a one long step to the right instead of a several small steps. Now I realize that there are bound to be some latency but I'm wondering how I can write my code to minimize it.
Currently the arrangement is non-persistent connection i.e the client requests a tcp socket transaction with the server for each command, afterwards that connection is closed. For example to move to the left the client must request a tcp socket connection with the server, send him the command (i.e move one square to the left) the server responds with an 'ok' and terminates the connection.
Could it be more appropriate to keep the connection open i.e the client is always connected to the server as in persistent connection? If so the server would have to maintain each of the client's socket on a seperate thread, since the server is in a endless loop listening for incoming connections?

I have another question but I will include it in another post, thank you.
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't care that the occasional packet gets lost, UDP is much better. There is a reason UDP is more often than not the protocol choice for real time apps.

How much information gets sent at one time? It is also possible that the worst bottleneck is not over the Internet, but somewhere in the client or server.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!