14

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"?

2
  • 1
    this is from programmers.stackexchange [how-a-port-listens-pull-or-push] describes in deep. [1]: programmers.stackexchange.com/q/107545/36957
    – Dinushan
    Sep 20, 2011 at 6:46
  • The answer describes the very low level mechanisms, below the notions of tcp/udp, ports and even listening, it's true for any network data reception.
    – Kevin
    Sep 20, 2011 at 7:39

2 Answers 2

13

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
1
  • that means Kernel will interrupt(notify) the process when this packet is received.
    – Dinushan
    Sep 20, 2011 at 6:39
7

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

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.