浏览器和网络服务器通信

发布于 2024-10-31 20:23:50 字数 139 浏览 2 评论 0原文

Web 服务器如何识别请求来自特定客户端?我知道通信是通过 http 协议进行的,但是是什么告诉服务器,对于特定请求,需要将响应发送到该客户端?

(我不确定这是否是一个太简单的问题,但我只是想在这里学习一些东西,并且也可能使像我这样的其他人受益)

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 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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千里故人稀 2024-11-07 20:23:50

HTTP服务器为每个连接的客户端启动一个新进程(在大多数情况下,它实际上启动一个新线程,但为了简单起见,我们可以假设它是一个进程),因此从代码中程序只能看到导致它启动的这个客户端。 HTTP 是无状态的,这意味着在完成对查询的回复后,http 服务器程序就结束了——它看起来像一个以查询为参数、以网页为返回值的函数。连接本身由源 IP、目标 IP、源端口和目标端口(所有这些)标识。

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).

揽月 2024-11-07 20:23:50

您的问题几乎此问题完全相同,其中有一些很好的答案。


响应通过请求所通过的同一 TCP/IP 连接返回。

客户端使用服务器的 IP 地址和端口发起该连接。服务器不需要知道客户端的 IP 地址和端口,因为连接已经打开并可供使用。

大多数[需要引用]客户甚至没有可公开访问的IP地址。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文