A connection is defined by the two IP addresses and two port numbers. Providing the set is unique it is a different connection so it is perfectly valid to have two remote devices connected to the same local IP address and port number providing the remote numbers are unique.
iOS didAcceptNewSocket expected different port number
-
01-07-2022 - |
题
I am using AsyncSocket and listening on a particular port. I correctly get a didAcceptNewSocket delegate callback with a new socket. When i call local for the new socket it has the same port number as my listen socket. I expected a different port.
- (void)createListenSocket
{
NSError *error;
listenSocket = [[AsyncSocket alloc] initWithDelegate:self];
[listenSocket acceptOnPort:MY_PORT_NUMBER error:&error];
}
and
- (void)onSocket:(AsyncSocket *)sock didAcceptNewSocket:(AsyncSocket *)newSocket
{
NSLog(@"new connected socket: local port: %d, connected port: %d",
[newSocket localPort], [newSocket connectedPort]);
This prints the value of MY_PORT_NUMBER for local port. Why?
解决方案
不隶属于 StackOverflow