Linux network sockets question

Hi guys,
I have probably a dumb question regarding sockets in linux networking.

When a server expects to recieve requests it needs to "bind" to a port so the kernel knows to redirect any packets for that port to the server.

My question is for the client which does not "bind" but just "connects". When the server sends data back to the client how does it get back to the client? There isn't a port that has been assigned to the client?

Thanks.
> When the server sends data back to the client how does it get back to the client?
> There isn't a port that has been assigned to the client?

When we call connect() the transport layer of the kernel would automatically choose an unused local port to identify our end of the connection.


> When the server sends data back to the client how does it get back to the client?

Each time the server calls accept(), it returns a new socket fd which is already connected to the client; this new socket is the one used to communicate with the client whose connection was accepted.

The optional output address argument is filled in with the socket address of the client; if it wants (if location-transparency is not desired), the server can use this address to determine the end point of the client.
https://www.freebsd.org/cgi/man.cgi?query=accept&apropos=0&sektion=2&manpath=FreeBSD+11.1-RELEASE+and+Ports&arch=default&format=html
Topic archived. No new replies allowed.