XCode iDevice 应用程序 - 如何侦听来自服务器的消息/请求? [英] XCode iDevice app - How to listen for message/request from server?

查看:42
本文介绍了XCode iDevice 应用程序 - 如何侦听来自服务器的消息/请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,我需要能够将消息从运行 Web 服务的服务器发送到特定的 iDevice.我不知道如何做到这一点,因此非常感谢您的帮助.

I have a project where I need to be able to send messages from a server running a web service to a specific iDevice. I have no idea how to do this, so any help is very appreciated.

场景:我有一个 Web 服务,它从 iDevice(也可以是 Mac 或 PC,甚至是 Android 设备)接收一些消息.根据此消息的内容,我需要能够将消息从 Web 服务发送到另一个 iDevice(我知道特定 iDevice 的 IP 地址).我知道如何使用 URLRequests 将消息从 iDevice 发送到服务器并从服务器收集响应.原则上我可以每 10 秒向服务器发送一个请求,询问服务器是否有任何新消息发送给发送者(iDevice 发送请求),但我很确定这不是正确的方法.有没有办法让 iDevice 侦听特定端口上的服务器通信,以便 iDevice 仅在收到来自服务器的消息以执行某些操作时才执行某些活动,例如在应用中显示一条监听服务器通信的消息?

The scenario: I have a web service which receives some message from an iDevice (could also be a Mac or PC, even an Android device). Depending on the content of this message I need to be able to send a message from the web service to another iDevice (I know the IP-address of the specific iDevice). I know how to use URLRequests to send a message from an iDevice to a server and collect the response from the server. In principle I could every 10 seconds send a request to the server asking if the server has any new messages to the sender (the iDevice sending the request), but I am pretty sure this is not the correct way to do it. Is there a way to have an iDevice listen for server communication on a specific port, so that the iDevice only does something active when it receives a message from the server to do something, e.g. display a message in the app listening for the server communication?

我想我需要使用类似于 iMessage 所用技术的东西,但这是如何做到的?

I guess I need to use something similar to the technology used for iMessage, but how is this done?

我使用的是 XCode 4.6.2,iOS 6.1.

I am using XCode 4.6.2, iOS 6.1.

只是为了进一步澄清我的需求:APNS 似乎太不可靠了(至少这是我在其他有关 APN 的线程中读到的内容),因为在某些情况下,Web 服务可能需要发送 2在 1 分钟(在某些情况下为几秒)内向 iDevice 发送不同的消息,据我在其他线程中读到,这根本不可能,因为 Apple 的服务器处理 ASPNS 的方式.

Just to clarify my needs a bit more: The APNS seems to be TOO unreliable (at least that is what I have read in other threads regarding APN) as the web service in some cases can have the need for sending 2 distinct message to an iDevice within 1 minute (in some cases seconds), and as far as I have read in other threads this will simply not be possible because of how Apple's server handles ASPNS.

我正在开发的应用程序只需要在应用程序处于活动状态时从服务器接收消息 - 有什么方法可以不使用 APNs 来做到这一点,例如让应用侦听特定端口上的通信?

The app i am developing only needs to receive messages from the server when the app is active - is there any way, not using APNs, to do this, e.g. making the app listen for communication on a specific port?

推荐答案

经过一番搜索,我决定不使用 APNS,因为人们似乎对它有各种经验.我无法使用 APNS,因为我的项目需要 100% 的可靠性和与服务器的即时通信.

After some search I have decided not to use the APNS, because it seems like people are having all sort of experience with it. I cannot use APNS because my project needs 100 % reliability and instant communication with the server.

我决定使用 tcp 通信,因为我的项目只会在本地网络中使用.这显然意味着 iDevices 的功耗会更高,但可靠性对项目来说更为重要.

I have decided to use tcp communication since my project only will be used in a local network. This will obviously mean more power consumption on the iDevices, but reliability is more crucial to the project.

这篇关于XCode iDevice 应用程序 - 如何侦听来自服务器的消息/请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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