[英]Polling asp.net MVC server from an Android client
After much research and bumping into the wall a couple of times, it's time to ask some questions. 经过大量研究并多次碰壁,是时候提出一些问题了。
I'm developing a project which is going to send a message from a web client to a server, then the server should notify multiple clients about the update, which should be done in seconds. 我正在开发一个项目,该项目将从Web客户端向服务器发送消息,然后服务器应将更新通知给多个客户端,这应在几秒钟内完成。
First I thought of using GCM notifications, but the user then have to push the notification in order for some code to run on the client (turning on gps and stuff) but my clients don't have time for clicking the notification when it arrives. 首先,我想到了使用GCM通知,但是用户必须推送通知,以便在客户端上运行一些代码(打开gps和东西),但是我的客户没有时间在到达通知时单击通知。 So it has to be done without user interaction.
因此,它必须在没有用户交互的情况下完成。
Next thing I thought about was if the android client could listen to the c# server and run code when the server had a new message, but I haven't found a working torturial yet. 我想到的下一件事是,如果Android客户端可以在服务器收到新消息时侦听c#服务器并运行代码,但是我还没有找到正常的运行环境。 I was looking into GCM again without push, just messages back and forward, but it's getting difficult to get to work.
我一直在没有推送的情况下再次查看GCM,只是来回传递消息,但是开始工作变得越来越困难。 Also sockets was a option, but it also seems really difficult to get to work and I'm not sure if those options are the way to go.
套接字也是一个选项,但是似乎也很难上班,我不确定这些选项是否可行。
So I was thinking to just let the android have a background service which is polling either a database or a method on my c# server. 所以我在想让android有一个后台服务,该服务在我的C#服务器上轮询数据库或方法。
Can anybody give me an idea of what is the right option and maybe a link to a tutorial which is a nice step by step thing. 谁能给我一个正确选择的想法,也许可以链接到教程,这是一步一步的好选择。
It could be nice if I had the option to also use it on IOS at a later point. 如果以后可以在IOS上使用它,那可能会很好。
If i understand correctly, what you are trying to do can be easily done by one of the following or more ways: 如果我正确理解,可以通过以下一种或多种方式轻松地完成您要尝试的操作:
1)Use GCM messages with a Payload! 1)使用有效载荷的GCM消息! When the mobile client receives the Notification it gets the Payload and proceeds on specific actions.
当移动客户端收到通知时,它将获得有效负载并继续执行特定操作。 http://developer.android.com/google/gcm/adv.html - http://developer.android.com/training/cloudsync/gcm.html#react
http://developer.android.com/google/gcm/adv.html - http://developer.android.com/training/cloudsync/gcm.html#react
2)Use a SyncAdapter
and make your app use an AlarmManager
which will periodically tell to the app to poll the server through the SyncAdapter
and check for new content. 2)使用
SyncAdapter
并让您的应用使用AlarmManager
,它会定期通知应用通过SyncAdapter
轮询服务器并检查新内容。 Another way of triggering the SyncAdapter
is sending a GCM notification like in the first step. 触发
SyncAdapter
另一种方法是像第一步一样发送GCM通知。 http://developer.android.com/training/sync-adapters/creating-sync-adapter.html http://developer.android.com/training/sync-adapters/creating-sync-adapter.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.