Android 与服务器的双工连接
我正在尝试在 android 设备和 .net 客户端应用程序之间创建双工连接(聊天应用程序)。我已经使用TCP连接实现了它。但由于某种原因我想实现一个基于 HTTP 的双工连接。中间层是一个 Web 服务器,它通过基于 SOAP 的 Web 服务进行通信。
当客户端向网络服务器发送消息时,它应该自动调用 Android 应用程序并显示消息。例如,如果 web 服务 getMessage() 为空,android 应用程序不应该执行任何操作,但如果有任何消息,则触发它并显示消息。
我在 C2DM 推送通知的帮助下实现了它。但我需要一个很好的解决方案,我需要在 Android 应用程序中实现某种侦听器,只有在有消息时才会调用该侦听器。当我做了一些研究时,我发现可以使用 asynctask 来完成,但即使 getMessage() 为空,它也会调用 onPostExecute() 方法。我想以这样的方式控制它,只有当消息不为空时,它才应该执行 onPostExecute() 方法。
我该如何实现这一目标?请传播一些光。 (请原谅你们见过的糟糕的英语)。
I am trying to create a duplex connection (Chat Application) between android device and the .net Client application. I have implemented it using TCP connection. But because of the some reason I would like to implement an HTTP based duplex connection. The middle tier is a webserver and it is communicating through SOAP based webservice.
When ever client sends a message to the webserver, it should automatically invokes the android application and displays the message. For example, if the webservice getMessage() is empty android app shouldnt do anything but if there is any message fire it and display the message.
I have implemented it with the help of C2DM Push Notification. But I need a nice solution, I need to implement some kind of Listener in Android application which only get invoked if there is some message. When I did some research I found out that, it can be done using asynctask, but even if the getMessage() is empty it will call the onPostExecute() method. I want to control it such a way that, only when message is not empty it should do the onPostExecute() method.
How do I achieve that? Kindly spread some light. (Excuse me for the terrible english you guyz have ever seen).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
顺便说一句,由于 C2DM 具有配额,因此将 C2DM 用于聊天应用程序确实是一个坏主意。相反,您应该考虑设置 XMPP 服务器并使用它进行通信。 Openfire 是一个很好的解决方案,而且安装非常简单。对于.NET客户端,您可以使用AgsXMPP,这是一个非常好的库。
抱歉,我的回答并没有真正回答您的问题,但它确实为您将来遇到的问题提供了建议。
On a side note, using C2DM for a chat application is a really bad idea because of the quota that C2DM has. Instead, you should think about setting up an XMPP server and communicating using it. Openfire is a nice solution and the installation is very simple. For the .NET client, you can use AgsXMPP which is a very nice library.
Sorry my answer doesn't really answer your question but it does offer advice on a problem you will encounter in the future.