端口监听到底是什么

发布于 2024-12-05 02:37:06 字数 56 浏览 0 评论 0 原文

“监听”端口是否意味着对该端口的连续轮询或离散轮询或中断驱动的过程。 “监听端口”究竟发生了什么?

Does "Listening" a port means a continuous polling to that port or a discrete polling or an interrupt driven process.
What exactly is going on in "Listening to a Port"?

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

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

发布评论

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

评论(2

自找没趣 2024-12-12 02:37:06

端口只不过是一个概念,它不像你可以检查一些内存位,等待一些信息。

因此,侦听端口将教导内核在接收具有该特定端口号的数据包时做什么:将其传输到要求侦听该端口的进程,而不是回复[或不]端口未打开。

注意:这只是猜测,我没有调查任何内核实现。

编辑:在进程方面,

  • listen< /a> 将告诉内核您对特定的交会端口感兴趣
  • (我不确定listenaccept之间会发生什么code>,内核要么缓冲新连接,要么拒绝它们,直到accept已被调用,请参考相关手册)
  • accept 将连接绑定到通信端口,并开始缓冲传入数据包
  • recv(或者当然是pollselect)将从接收缓冲区中拾取数据

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 port
  • (I'm not sure what happens between listen and accept, either the kernel buffers the new connections or rejects them until accept has been called, please refer to the relevant manual)
  • accept will bind the connection to a communication port, and start buffering the incoming packets
  • recv (or poll or select certainly) will pickup data from the reception buffer
云雾 2024-12-12 02:37:06

内核从传入的 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".

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