multithreading Web 浏览器是否对打开的选项卡使用不同的端口号?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6632801/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Do Web browsers use different port numbers for open tabs?
提问by Haitham A. El-Ghareeb
I'm wondering how browsers internally works. Now, connecting to different Web sites using 'Tabs' within the same browser can be handled in one of two ways: 1 - Using threads 2 - Using Different Source Port Numbers for each open tab
我想知道浏览器内部是如何工作的。现在,可以通过以下两种方式之一在同一浏览器中使用“选项卡”连接到不同的网站: 1 - 使用线程 2 - 为每个打开的选项卡使用不同的源端口号
I know there might not be a single answer for this question, and it might differ from one browser to another, however all responses are appreciated.
我知道这个问题可能没有一个单一的答案,而且它可能因浏览器而异,但是所有的回答都值得赞赏。
Thanks
谢谢
Thanks for everyone.I really appreciate that. My question relates to the Source Port at the client side. I'm asking if the browser uses different source ports for each tab it opens, or the same source port for the entire process 'I mean window that includes different tabs', or the same source port for the entire windows?
谢谢大家。我真的很感激。我的问题与客户端的源端口有关。我在问浏览器是否为它打开的每个选项卡使用不同的源端口,或者整个过程使用相同的源端口“我的意思是包含不同选项卡的窗口”,还是整个窗口使用相同的源端口?
Or, do web browsers use threads?
或者,网络浏览器是否使用线程?
回答by Ribose
Threads and ports are separate and mostly unrelated concepts.
线程和端口是独立的并且几乎不相关的概念。
Threads are what the local computer processor does to handle computations, such as drawing to the screen or waiting for Internet traffic. There's probably a separate thread (and more) for those operations in each tab.
线程是本地计算机处理器用来处理计算的东西,例如在屏幕上绘制或等待 Internet 流量。每个选项卡中的这些操作可能有一个单独的线程(以及更多)。
Ports are what the traffic itself is identified by (in TCP and UDP). In order to communicate your browser would open a local port (usually something big like ~5000, and that doesn't matter as long as its unique) and connect to the server on usually port 80 (the one the server is listening on). If your computer didn't know the remote port it couldn't connect, but its standard to use 80 for HTTP, for example.
端口是流量本身所标识的(在 TCP 和 UDP 中)。为了进行通信,您的浏览器会打开一个本地端口(通常是大约 5000 之类的大端口,只要它是唯一的就没有关系)并通常在端口 80(服务器正在侦听的端口)上连接到服务器。如果您的计算机不知道它无法连接的远程端口,但它的标准是使用 80 来表示 HTTP,例如。
Browsers open tabs in separate threads (and new ones even in separate processes for security and reliability reasons), and use separate ports on the client side. So yes, the answer is both threads and ports. They always use the same remote port unless you physically specify otherwise (for example, connecting to a website using https:// instead of http:// uses a separate port because that's how that protocol was made). You can specify a port to use in modern browsers with :# after the name, too. (example: http://www.google.com:81/, however that will fail because that's not what port they listen on!)
浏览器在单独的线程中打开选项卡(出于安全和可靠性的原因,甚至在单独的进程中也会打开新的选项卡),并在客户端使用单独的端口。所以是的,答案是线程和端口。它们始终使用相同的远程端口,除非您以其他方式物理指定(例如,使用 https:// 而不是 http:// 连接到网站使用单独的端口,因为该协议就是这样制定的)。您也可以在名称后使用 :# 指定要在现代浏览器中使用的端口。(例如:http://www.google.com:81/,但是这会失败,因为那不是他们监听的端口!)
回答by vinod
A quick check using netstat
(or sockstat
on BSD machines) reveals that different source port numbers are used for different connections. In that regard, you are right.
使用netstat
(或sockstat
在 BSD 机器上)快速检查显示不同的源端口号用于不同的连接。在这方面,你是对的。
Firefox uses at least one thread for each tab. Each thread could open multiple connections for different data (for example, loading images from a media server and content from the web server). Each connection should have its own source port.
Firefox 为每个选项卡使用至少一个线程。每个线程可以为不同的数据打开多个连接(例如,从媒体服务器加载图像和从 Web 服务器加载内容)。每个连接都应该有自己的源端口。
回答by Abdullah Jibaly
Depending on the browser it uses different threads or different processes for each tab. The local ports used probably don't have much to do with different tabs.
根据浏览器的不同,它为每个选项卡使用不同的线程或不同的进程。使用的本地端口可能与不同的选项卡没有太大关系。
回答by Michael Stum
Do you mean TCP Ports? No, Browsers use the same port, usually 80 or 443 (for HTTPS).
你的意思是TCP端口?不,浏览器使用相同的端口,通常是 80 或 443(用于 HTTPS)。
HTTP is a stateless protocol: The browser opens a connection, loads a page, then closes it. It doesn't hold the connection. If you load more than 1 page then it creates threads for each (usually, Chrome creates processes) but as soon as the page is loaded the connection is closed.
HTTP 是一种无状态协议:浏览器打开一个连接,加载一个页面,然后关闭它。它不保持连接。如果您加载了 1 个以上的页面,那么它会为每个页面创建线程(通常,Chrome 创建进程),但是一旦加载了页面,连接就会关闭。
AJAX opens a new connection for each request and closes it afterwards.
AJAX 为每个请求打开一个新连接,然后关闭它。
There are some Hacks to have a persistent HTTP Connection (See COMET), but because the browser runs multiple threads/processes they don't conflict usually.
有一些 Hacks 具有持久的 HTTP 连接(参见 COMET),但由于浏览器运行多个线程/进程,它们通常不会发生冲突。
回答by shobhonk
no! it usually uses port 80 by default unless specified. for example www.someweb.com:8080.
不!除非指定,否则它通常默认使用端口 80。例如 www.someweb.com:8080。
Tabs within browser i am assuming ran on different threads
我假设浏览器中的标签在不同的线程上运行