1 of 3

how the server comes to know about the client port to whom server needs to send data?

As per my understanding below are the following steps when a client makes a 
connection request.
1.Server will be binded to a particular port number.Always port number is 
binded only to the process which listens.Since only server is listening for
incoming connections,we dont have bind in client side.
2.Server will be keep on listeninig on that port number.
3.Client will send connect() request.
4.Server will accept the request using accept().As soon as the server 
accepts the client request,kernel allocates a random port number for the 
server for further send and receive().Because same port number of the 
server cant be used for sending as well as listening.Because the previous
port need to listen for other incoming connections too.But from which 
function() server comes to know about the client port ?I know that client 
will send TCP segments with source port and destination port.So server will
use the source  port of that segment as its destination port.But program 
wise if we are thinking then from which function is the server fetching the
client port details.Is it accept() ?If server needs to send data to 
client,it need to know the port number of the client right?Any body pls 
help me on understanding this concept.