1

I have some key question in developing the server of a multiplayer game. I need the best concept then I will use that in both C# and PHP. Currently I want to make a game like this:

online multiplayer racket game

The button racket is mine and the upper is yours. I need to transfer the data every 40 milliseconds to refresh the screen. The first idea was that I write a web service that computes the current position of the objects and respond to the clients as JSON.

But the problem was the data on server. I couldn't share the session data across the clients. I thought to use DB but it was slow enough to not to use! Is it any way to share data between different clients of one web service?

And the second question: is it good to use web services? I thought of sockets but the thing is how much ports do we have on the server to answer to the clients requests? And if the web services are good to use, then how can I advance the time of the game in the server when any client is not requesting data and web service is down?

halfer
  • 19,824
  • 17
  • 99
  • 186
ConductedClever
  • 4,175
  • 2
  • 35
  • 69
  • This looks like a *very* small amount of data. (Basically a single X-coordinate for each player's current position. So, two integers.) Surely storing two integers in active memory on a web service isn't prohibitively slow... – David May 16 '15 at 10:15
  • what do u mean by `how much ports do we have on the server to answer to the clients requests?` – karthik manchala May 16 '15 at 10:21
  • @David what do you mean by saying active memory of web service? – ConductedClever May 16 '15 at 11:42
  • @karthikmanchala I mean that if i spend one port of the server for each game, then the number of ports won't be enough! isn't that right? – ConductedClever May 16 '15 at 11:43
  • each game? you mean each instance of the game? if so.. you dont need to spend one port per instance.. example database runs on a single port responding to many requests and maintaining many connections in parallel.. – karthik manchala May 16 '15 at 11:49
  • @karthikmanchala yes i mean each instance. So you mean that a socket is enough for whole the players? or just sharing between some of them? thanks for your answer. – ConductedClever May 16 '15 at 12:14
  • @ConductedClever: Well, does the current state of any given game need to survive a server failure? For this game, it doesn't seem so. So an in-memory database or even just a static hash table of values in the application should do the trick. – David May 16 '15 at 12:29
  • are you sure you need to transfer an update every 40ms? Can't you send data on position, direction, and velocity – and update only if they change? – Beat May 16 '15 at 13:32
  • @Beat every thing will be calculated on server and the client will read object positions and game result every frame from server. – ConductedClever May 16 '15 at 15:13

1 Answers1

1

Sockets, in general are much faster than web services. You can use them in your implementation.

I thought of sockets but the thing is how much ports do we have on the server to answer to the clients requests

They don't require a port for each connection. One port is required for the service and you can instantiate many socket objects between client and server.

karthik manchala
  • 13,492
  • 1
  • 31
  • 55