How is an HTTP response sent back to fix the client in TCP?

I am trying to understand how an HTTP server provides the right response message to the right client.

At a very high level:

  • At the TCP server level, the ServerSocket server implementation (listening on the host: port to which the request was sent) creates a "client socket" to process the request

  • (if we assume that this is a streaming server) - a thread is allocated in the application and work is done

Questions: -

A.) Should the response be returned through the same Socket that handled the request?

B.) If so, how does the response respond to the same socket that processed the request?

C.) Is it the responsibility of the socket to maintain the IP address of the client that the return packets should access, or are the HTTP headers that support this information and which are then used to respond to the correct client response?

If the HTTP header information is used to redirect the response to the calling client, I believe that the response does not have to be handled by the same socket that was handling the associated request

Any help is greatly appreciated. James

+4
source share
1 answer

Sockets are bidirectional.

ServerSocket , Socket , . . , . IP/ , . , .

+3

All Articles