在 iPhone 上监听 Co​​coaASyncSocket 接收连接,但新套接字不调用委托

发布于 2024-10-03 15:25:02 字数 531 浏览 5 评论 0原文

我正在尝试通过指定 IP 来实现两个设备之间的基本消息传递。当一台设备告诉其侦听套接字按如下方式进行侦听时:

UInt16 port = 59647;
NSError *err = nil;
[socket acceptOnPort:port error:&err];

didAcceptNewSocket 委托被正确调用,并且应该向连接 IP:Port 返回一个新套接字。然而,据我所知,它正在执行此操作,然后新套接字应该调用 didConnectToHost,但据我所知,事实并非如此。

didConnectToHost 已正确实现,因为发起与其套接字连接的设备在建立连接后正确调用它。

除了一些 NSLogs 并将旧的监听套接字设置为新的监听套接字(因为之后不需要它,并将其分配给一个之前的不同变量没有改变任何东西,也不应该改变)。

什么可以使侦听端的新套接字不调用该委托?

I'm trying to implement basic message pasing between two devices by specifying IPs. When one device tells its listening socket to listen as follows:

UInt16 port = 59647;
NSError *err = nil;
[socket acceptOnPort:port error:&err];

The didAcceptNewSocket delegate is called correctly, and should return a new socket to the connecting IP:Port. As far as I can tell it's doing this, however, the new socket should be then calling didConnectToHost, which as far as I can tell it is not.

didConnectToHost is implemented correctly, as the device which initiates the connection with its socket properly calls it after the connection has been established.

I'm not doing anything in didAcceptNewSocket aside from a few NSLogs and setting the old listening socket to the new one (as its not needed after, and having it assigned to a different variable before didn't change anything, nor should it).

What could make my new socket on the listening side not call this delegate?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

做个少女永远怀春 2024-10-10 15:25:02

由于您正在处理客户端和服务器,因此重要的是要认识到只有客户端才会调用 socket:didConnectToHost:port: 委托方法,因为它是连接到主机的客户端(而不是反之亦然)。

在服务器上,使用侦听套接字作为第一个参数来调用 socket:didAcceptNewSocket: 委托方法。

Since you are dealing with a client and a server, it is important to realize that only the client will invoke the socket:didConnectToHost:port: delegate method as it is the client who connects to a host (not the other way around).

On the server, the socket:didAcceptNewSocket: delegate method is invoked with the listening socket as the first argument.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文