Mark
Mark

Reputation: 6494

is is possible to bind TCP socket to many ports?

I see that some applications using TCP can be configured to bind to multiple ports. Does this mean that they open multiple TCP sockets, or it is possible to open a single socket and bind it to many local ports?

Thanks.

Upvotes: 1

Views: 84

Answers (1)

Jeremy Friesner
Jeremy Friesner

Reputation: 73304

A TCP socket can only be bound to a single port. In particular, if you try to bind an already-bound TCP socket to a second port, bind() will return -1 and set errno to EINVAL.

Servers that accept incoming TCP connections on multiple ports are doing it by creating multiple TCP sockets.

Upvotes: 1

Related Questions