5

The netstat(8) man page states "Show both listening and non-listening (for TCP this means established connections) sockets. With the --interfaces option, show interfaces that are not marked"

What is a non-listening socket vs a listening socket? Does it still occupy the port? or is the port free to be used by other programs?

jww
  • 97,681
  • 90
  • 411
  • 885
xavierc
  • 502
  • 2
  • 13
  • 1
    https://linux.die.net/man/2/listen – hnefatl Jan 09 '19 at 21:33
  • The answer has to do with listening sockets which are usually implemented by programmers. I guess it could go on server fault, it's pretty on the fence imo – xavierc Jan 16 '19 at 21:35

2 Answers2

6

Sockets run a state machine. They wait, then respond to requests. One of the states is 'LISTEN'.

Non-listening is every other state, in other words when something is happening or a connection is established.

There's a good TCP state diagram with state descriptions here. I've provided a reduced size version here, in-case the link ever breaks.

enter image description here

Elliptical view
  • 3,338
  • 1
  • 31
  • 28
5

A listening socket is one where the server process is waiting for someone to connect to it, for example, an idle web server. The port it is listening on is considered in use.

A non-listening socket is one where a connection has been made, for example, a web server where a web client, such as a browser, has connected, and data can be or is being transmitted. The port the socket was listening on is usually then also cycled back to be listened on by the same process or process tree.

Tanktalus
  • 21,664
  • 5
  • 41
  • 68