0
\$\begingroup\$

I have a game where I have to get data from the server but the problem is I don't know when the data will become available on server. So I decided to use co-routine and hit server at after specific time or on every frame. But certainly this is not the right, scale able and efficient approach.

Now my question is that how do I know that data has arrived at server so that I can use this data to run my game. Or how should I direct the back-end team to design the server in an efficient way that it responds efficiently.

Our back-end team currently uses REST Web services with JSON with Python. And they want to push data to my unity player without my frequent requests.

\$\endgroup\$
7
\$\begingroup\$

REST is not the right paradigm for bidirectional communication, because with REST you can not send data which wasn't specifically requested. Hammering the server with repeated requests is not a good solution because it generates lots of unnecessary network traffic and still gives you additional delays up to the length of your hammering interval.

But there is a workaround: Long-Polling. The client makes a request and the server artificially delays the response until there is something worth sending.

If you don't want to do long-polling, you might want to use a different technology. When the game is browser-based, then Websockets would be a solution. An established websocket connection allows both client and server to send data at any time.

When your game is not browser-based, then you might want to implement your own protocol on raw TCP or UDP sockets.

You flagged this question with unity. When your game client is programmed in Unity, you could use the Unity network system which internally uses WebSockets when you export as a HTML5 application and UDP on most other platforms.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Thanks Philipp for valueable input and teaching me so of the terms like hammering, Long-polling. but i have some questions \$\endgroup\$ – Muhammad Faizan Khan Oct 12 '17 at 11:59
  • \$\begingroup\$ Remember the communction in not bidrectional it will unidirectional. I can only request from my client Unity3d Application. \$\endgroup\$ – Muhammad Faizan Khan Oct 12 '17 at 11:59
  • \$\begingroup\$ Long polling seems interesting. is there any unity specific demo available? \$\endgroup\$ – Muhammad Faizan Khan Oct 12 '17 at 12:00
  • \$\begingroup\$ @MohammadFaizanKhan When you use long-polling with the Unity WWW class, then there is nothing unity-specific about it. The coroutine which does the request will return from yield return www; whenever the response from the server arrives. The relevant part is on the webserver which serves that request. But you didn't say what technology you are using for that. If your backend team has questions about implementing long-polling, they should ask those separately. \$\endgroup\$ – Philipp Oct 12 '17 at 12:03
  • \$\begingroup\$ The only fact i know about the back-end team that they are using Web service REST with JSON \$\endgroup\$ – Muhammad Faizan Khan Oct 12 '17 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.