I know this question seems typical and multiple times answered but I think if you read the details it is not so common (I did not find it).
The poin
Statefull connection is uniquely identified by two end points Peer(address:port)<=>My(address:port). Both getpeername() and getsockname() are needed to get this information.