了解长轮询:客户端(Android)和服务器(ASP网) [英] Understanding long polling: client (android) and server (asp net)

查看:137
本文介绍了了解长轮询:客户端(Android)和服务器(ASP网)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Android应用程序,用户可以在某种战斗的竞争。在服务器端,我需要接收来自用户的请求,开始战斗,然后使用一些算法,请选择对他最preferable对手。在一次战斗我也需要发送通知给他们的对手的行动竞争对手。

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. 服务器端。我使用asp.net mvc的服务器。我看了一下 SignalR 框架,它似乎正是我需要的。然而,仅仅因为我是新来长轮询,我不明白其内部工作原理。所以,我需要关于如何使用这个框架,或如何实现长轮询一些其他的方式解释。

  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.

客户端。据我了解,长轮询请求模型略有标准的请求 - 响应的模式不同,所以我也想知道如何实现客户端这些请求一面。

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.

推荐答案

这可能不是你正在寻找的答案,但你为什么想要去的长轮询。你可以做样的投票对于这种类型的通知的IF 你只轮询当用户从事战斗。结果这样,电池的寿命也将被保存。
当战斗开始,启动后台服务,它轮询服务器每 2-3秒(希望2-3秒的延迟是可以接受的)。并相应地通知用户。然后,当战斗结束停止该服务。结果
这将是更容易实现。
结果
但是如果你需要即时通知,您可以使用谷歌的云信息服务(它是长轮询的一种形式)。为了更多地了解它是如何工作的,请参见

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

这篇关于了解长轮询:客户端(Android)和服务器(ASP网)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆