浏览器如何在80端口上与Web服务器建立连接?细节? [英] How does a browser establish connection with a web server on 80 port? Details?

查看:244
本文介绍了浏览器如何在80端口上与Web服务器建立连接?细节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(这个问题的灵感来自对这个主题的回应: WebSocket服务器如何处理多个传入连接请求?

(This question is inspired by a response to this thread: How WebSocket server handles multiple incoming connection requests?)

我的理解是这样的:

假设客户端IP = 1.1.1.1,服务器IP = 9.9.9.9

Assume client IP = 1.1.1.1, server IP = 9.9.9.9


  1. 浏览器选择随机本地可用端口,比如5555,并启动与服务器端口80的连接。所以在客户端, socketfd_client 应代表一个IP连接,如(1.1.1.1:5555, 9.9.9.9:80,TCP)

  1. Browser choose a random local available port, say 5555, and initiate a connection to server's port 80. So on client, the socketfd_client should represent an IP connection like (1.1.1.1:5555, 9.9.9.9:80, TCP).

服务器调用 accept()在其端口80上并识别来自客户端的连接请求。然后,服务器选择一个随机的本地可用端口,例如8888,以满足该连接请求。所以在服务器上, socketfd_server 应代表一个IP连接,如(1.1.1.1:5555,9.9.9.9:8888,TCP)

Server calls accept() on its port 80 and identified the connection request from client. Then server picks a random local available port, say 8888, to fulfill that connection request. So on server, the socketfd_server should represent an IP connection like (1.1.1.1:5555, 9.9.9.9:8888, TCP).

我的问题是:

如果我的上述理解是正确的, socektfd_client socketfd_server 有不同的服务器端口。客户端有80,而服务器有8888.如何进行通信?我认为客户端应该改为使用服务器端口8888,但是何时以及如何使用?

If my above understanding is correct, socektfd_client and socketfd_server have different server port. Client has 80 while server has 8888. How could the communication be carried out? I think client should change to use the server port 8888 as well, but when and how?

推荐答案


浏览器选择一个随机的本地可用端口,比如5555

Browser choose a random local available port, say 5555

否。 操作系统执行此操作:具体而言,是网络堆栈的TCP部分。

No. The operating system does that: specifically, the TCP part of the network stack.


并启动与服务器的端口80.所以在客户端,socketfd_client应该代表一个IP连接,如(1.1.1.1:5555,9.9.9.9:80,TCP)。

and initiate a connection to server's port 80. So on client, the socketfd_client should represent an IP connection like (1.1.1.1:5555, 9.9.9.9:80, TCP).

正确。


服务器在其端口80上调用accept()并识别来自客户端的连接请求。

Server calls accept() on its port 80 and identified the connection request from client.

正确。


然后服务器选择一个随机的本地可用端口,比如8888

Then server picks a random local available port, say 8888

否。


满足该连接请求。

to fulfill that connection request.

否。


所以在服务器上,socketfd_server应代表一个IP连接,如(1.1.1.1:5555,9.9.9.9:8888,TCP)。

So on server, the socketfd_server should represent an IP connection like (1.1.1.1:5555, 9.9.9.9:8888, TCP).

没有。两端的连接由 {1.1.1.1:5555,9.9.9.9:80} 表示。服务器端没有新端口。

No. The connection at both ends is represented by {1.1.1.1:5555, 9.9.9.9:80}. There is no new port at the server end.


我的问题是:

My question is:

如果我的上述理解是正确的

If my above understanding is correct

不是。


socektfd_client和socketfd_server有不同的服务器端口。

socektfd_client and socketfd_server have different server port.

否。


客户端有80,而服务器有8888.如何进行通信?我认为客户端应该改为使用服务器端口8888,但是何时以及如何?

Client has 80 while server has 8888. How could the communication be carried out? I think client should change to use the server port 8888 as well, but when and how?

从不。

这篇关于浏览器如何在80端口上与Web服务器建立连接?细节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆