Listening for CocoaASyncSocket on an iPhone receiving a connection, but the new socket does not call a delegate

I am trying to implement basic messaging between two devices by specifying IP addresses. When one device tells the listening socket to listen to the following:

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

The delegate didAcceptNewSocketis called correctly and should return a new socket to the connecting IP: Port. However, as far as I can tell about this, a new socket should then be called didConnectToHost, which, as far as I can tell, this is not so.

didConnectToHost runs correctly, because the device that initiates the connection to its socket correctly calls it after the connection is established.

I do nothing in didAcceptNewSocketbut a few NSLogsand set the old socket to listen to in a new one (since it is not needed after, and binding to another variable before it has changed nothing, and should not).

What can my new socket on the listening side do not call this delegate?

+3
source share
1 answer

Since you are dealing with a client and server, it is important to understand that only the client will call the delegate method socket:didConnectToHost:port:, since it is the client that connects to the host (and not vice versa).

On the server, the delegate method socket:didAcceptNewSocket:is called using the listen socket as the first argument.

+1
source

Source: https://habr.com/ru/post/1775916/


All Articles