简体   繁体   English

iPhone UDP侦听器

[英]iPhone UDP listener

I'm in need of some advice for how to accomplish something. 我需要一些有关如何完成某事的建议。

I'd like my iPhone app to listen for information from my server and then my server will send out data to all listening devices. 我希望我的iPhone应用程序从服务器监听信息,然后服务器将数据发送到所有监听设备。

A few questions: 几个问题:

  1. Will the iDevice need to "register" with the server with its IP? iDevice是否需要使用其IP向服务器“注册”? So, then on the server side, I store all listening device IPs in an array and fire out data to each. 因此,然后在服务器端,我将所有侦听设备IP存储在一个阵列中,并将数据发送到每个IP。
  2. Is there away for it to simply listen without the initial message? 是否可以简单地收听而无需初始消息呢?
  3. Is UDP the way to go on this? UDP是继续这样做的方法吗? Obviously I don't want a TCP stream because it's a constant connection. 显然,我不需要TCP流,因为它是一个恒定的连接。 Uses too much data. 使用太多数据。 My goal is use the least amount of data possible to receive a small timestamp from a server. 我的目标是使用尽可能少的数据量来从服务器接收较小的时间戳。

Any suggestions would be appreciated! 任何建议,将不胜感激!

Elijah 以利亚

If you do not want to use Apple Push Notifications, and you don't want to use long polling, I would look into something like websockets . 如果您不想使用Apple Push Notifications,并且不想使用长时间轮询,那么我会研究诸如websockets之类的东西。

PHP has a very good implementation for it (I assume PHP is your server side language?) in Ratchet . PHP在Ratchet中对此有一个非常好的实现(我假设PHP是您的服务器端语言?)。

EDIT: 编辑:

Just to elaborate a little, WebSockets will allow you to transmit from the server directly to the apps of every connected user at once, just like you are asking. 稍微说明一下,WebSockets可以让您立即从服务器直接传输到每个已连接用户的应用程序,就像您要的一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM