browser and web server comm
how does a web server identify that the request is from a specific client? i know the communication happens through http protocol but what is it that tells the server开发者_StackOverflow中文版 that, for a particular request, the response needs to be sent to this client?
(i am not sure if this is too simple a question but i just want to learn something here and may benefit others like me as well)
The HTTP server starts a new process (in most cases, it actually starts a new thread, but for simplicity's sake we can assume it's a process) for every client that connects, so from code the program sees only this client that caused it to start. HTTP is stateless, which means that after it's done replying to the query, the http server program ends - it looks like a function with the query as the parameter and the web page as the return value. The connection itself is identified by Source IP, Destination IP, Source Port and Destination Port (all of them).
Your question is almost an exact duplicate of this question, which has some good answers.
The response goes back over the same TCP/IP connection that the request came over.
The client initiated that connection with the server's IP address and port. The server does not need to know the IP address and port of the client, because the connection is already open and ready for use.
Most[citation needed] clients don't even have a publicly accessible IP address.
精彩评论