Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Persistent or non-persistent connection?

Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
    Bookmark Topic Watch Topic
  • New Topic