端口监听到底是什么
“监听”端口是否意味着对该端口的连续轮询或离散轮询或中断驱动的过程。 “监听端口”究竟发生了什么?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
“监听”端口是否意味着对该端口的连续轮询或离散轮询或中断驱动的过程。 “监听端口”究竟发生了什么?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
端口只不过是一个概念,它不像你可以检查一些内存位,等待一些信息。
因此,侦听端口将教导内核在接收具有该特定端口号的数据包时做什么:将其传输到要求侦听该端口的进程,而不是回复[或不]端口未打开。
注意:这只是猜测,我没有调查任何内核实现。
编辑:在进程方面,
listen
< /a> 将告诉内核您对特定的交会端口感兴趣listen
和accept
之间会发生什么code>,内核要么缓冲新连接,要么拒绝它们,直到accept
已被调用,请参考相关手册)accept
将连接绑定到通信端口,并开始缓冲传入数据包recv
(或者当然是poll
或select
)将从接收缓冲区中拾取数据A port is nothing more than a concept, it's not like if you could check some memory bits, waiting for some information.
So, listening to a port will teach the kernel what to do upon receiving packets with this specific port number: transmit it to the process which asked to listen on that port, instead of replying [or not] that the port in not open.
NB: that's just speculations, I didn't investigate any kernel implementation.
EDIT: On the process side,
listen
will tell the kernel that you're interested in a particular rendez-vous portlisten
andaccept
, either the kernel buffers the new connections or rejects them untilaccept
has been called, please refer to the relevant manual)accept
will bind the connection to a communication port, and start buffering the incoming packetsrecv
(orpoll
orselect
certainly) will pickup data from the reception buffer内核从传入的 IP 数据包中提取目标端口,然后将数据包转发到为此特定端口注册的所有接收者(是的,可能有多个)。用户进程通常使用 select(2) 或 poll(2) 来等待事件,但这种轮询与传统的轮询(如“读 I/O 端口;延迟 500 ms”)不同。
The kernel extracts the destination port from incoming IP-packets and then forwards the packet to all receivers, that registered for this specific port (yes, there may be multiple). A user process normally uses select(2) or poll(2) to wait for an event, but this poll is different from the traditional polling like "read I/O port; delay 500 ms".