Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding long polling: client (android) and server (asp net)

I'm developing android application where users can compete in some kind of battles. On the server side I need to receive requests from user for starting a battle, and then, using some algorithm, choose the most preferable opponent for him. During a battle I also need to send notifications to competitors about their opponent's actions.

So it seems that I need to implement long polling on my server. My questions are:

  1. Server side. I'm using asp.net mvc server. I had a look at SignalR framework and it seems to be just what I need. However, just because I'm new to long polling, I haven't understood its internal principles of work. So I need explanations on how to use this framework, or how to implement long polling some other way.

  2. Client side. As far as I understood, long polling requests model slightly differs from standard "request-response" model, so I'm also wondering how to implement these requests on client side.

I'm looking forward to any explanations on subjects that I've described.

like image 636
Yury Pogrebnyak Avatar asked Oct 26 '12 00:10

Yury Pogrebnyak


2 Answers

This might not be the answer you are looking for, but why do you want to go for long polling. you can do the "pull" kind of polling for this type of notifications IF you are only polling when the users are engaged in battles.
This way battery life will also be saved. When the battle starts, start a background service, which polls the server every 2-3 seconds(hope a latency of 2-3 seconds is acceptable). And notify the user accordingly. Then stop the service when the battle is over.
This will be far more easier to implement.
But if you need instantaneous notification, you can use Google Cloud Messaging Service(it is a form of long-polling). To know more about how it works, see this

like image 129
Ashwin Avatar answered Oct 01 '22 02:10

Ashwin


I am not sure, if you have considered WCF.

Take a look onto this, see if it helps you. http://anthymecaillard.wordpress.com/2012/06/06/wcf-real-time-web-development-with-long-polling/

For client: Use Jquery, with progress wheel showing till our response is back from the server

like image 43
Nipun Ambastha Avatar answered Oct 01 '22 03:10

Nipun Ambastha