Reputation: 1708
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?
Upvotes: 1
Views: 448
Reputation: 1708
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.
Upvotes: 1