3
votes
int accept(int socket, struct sockaddr *restrict address,socklen_t *restrict address_len);

The accept method receive a listen fd socket and return a conn fd. Of course they are different. But the two socket have the same port, why they are different?

listen method listen connection, if tcp 3 way handshake finished, the socket becomes acceptable. How do the listen socket transfer tcp connection to the new conn fd socket during accept?

1

1 Answers

7
votes

But the two socket have the same port, why they are different?

Because otherwise you could never have more than one simultaneous client. The accepted socket also has a peer IP address and port, which the listening socket doesn't have.

How do the listen socket transfer tcp connection the new conn fd socket during accept?

It doesn't 'transfer' anything. accept() creates a new socket with the connection details.