开发者

Listening CocoaASyncSocket on iPhone receiving connection but new socket does not call delegate

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 开发者_JAVA技巧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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜