How does a server handle multiple requests, and how does is know where to send which response?

25 views Asked by At

I am trying to figure out how a server handles multiple concurrent requests and each client receive the response to their own request. I did read a few answers online but those confused me even more.

From what I understand a client establishes a TCP connection with the server using a 3-way handshake, then the client sends a request, and for each request the server gets a thread from the threadpool, the ethernet frame is deencapsulated to get the request data, each request gets independently processed within its thread, and the response is sent back to the client.

So, is this process correct; if yes, how does the server know which IP to send the response back to since that info gets lost during deencapsulation? And what if the server is single threaded like nodejs, does each request get its response sequentially? If not, why don't the responses get mixed up?

It would be really helpful if someone could resolve these doubts. Thanks!

0

There are 0 answers