简体   繁体   English

如何在Objective-C中侦听网络端口

[英]How to listen on a network port in Objective-C

I am trying to make an application for iPhone that can listen for traffick on a specific network port. 我正在尝试制作一个可以侦听特定网络端口上的流量的iPhone应用程序。

A server on my network is sending out messages (different status messages for devices the server handles) on a specific port. 我的网络上的服务器正在特定端口上发送消息(服务器处理的设备的不同状态消息)。

My problem is that when I make a thread and makePairWithSocket I block the port for others who want to send messages to the server, so I only want to listen to the traffic on a specifyed port and then check for specific heraders and then use those messages. 我的问题是,当我创建一个线程和makePairWithSocket时,我阻止其他人想要向服务器发送消息的端口,所以我只想听取指定端口上的流量,然后检查特定的heraders然后使用这些消息。 I know how to make the connection and talk to the server using write and read streams, but then I makePairWithSocket and block the port for all other devices on the network 我知道如何建立连接并使用写入和读取流与服务器通信,但后来我makePairWithSocket并阻止网络上所有其他设备的端口

Any one that has any suggestions on how to listen on a port in Objective-C without pairing with the server? 有没有关于如何在没有与服务器配对的情况下监听Objective-C中的端口的任何建议?

Thanks in advance Daniel 在此先感谢丹尼尔

Check out CocoaAsyncSocket. 看看CocoaAsyncSocket。 It gives you a nice and structured way (with delegates) to send and receive data... also with multiple clients. 它为您提供了一个很好的结构化方式(有代表)来发送和接收数据......还有多个客户端。 The documentation is quite good. 文档非常好。 project link 项目链接

edit: Have a look at the AsyncUdpSocket class for a stateless UDP connection. 编辑:查看无状态UDP连接的AsyncUdpSocket类。

我认为这需要远低于套接字API级别的网络支持,可能是在硬件驱动程序级别,假设数据包甚至被路由到您的设备。

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

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