BrandonPotter / SimpleTCP

Straightforward .NET library to handle the repetitive tasks of spinning up and working with TCP sockets (client and server).
Apache License 2.0
365 stars 108 forks source link

Add option to listen on 0.0.0.0 instead of individually on all interfaces #27

Open brudo opened 6 years ago

brudo commented 6 years ago

I am suggesting to add an option to bind 0.0.0.0 to listen on all interfaces in SimpleTcpServer, instead of itemizing the interfaces and listening on each one individually. This would work well on Windows but might not be supported on all platforms, e.g. Linux, so you may need to make this configurable through an optional parameter, or have the check which OS at run time, or have it try 0.0.0.0 and fall back to individual interfaces if that fails. Thoughts?

BrandonPotter commented 6 years ago

What would be the advantages of 0.0.0.0 vs individual interfaces?

brudo commented 6 years ago

Avoids having to enumerate interfaces and listen separately on each, and dealing with any errors on each interface, but I guess that’s more of an internal detail (that I see as beneficial), not a use case. It’s how I usually bind on Windows by default, i.e. IPAddress.Any, unless configured otherwise. If I’m not mistaken - and I could be wrong - it could also handle cases where a network interface comes online or gets reconfigured after the server has been started.

There are other differences; whether they are advantageous or not depends on context. Can be overridden by bindings for specific interfaces, when you want that. Will not silently override another service listening on same port, e.g. if the other service is listening on the same port on 0.0.0.0, your bindings on each interface will take precedence, IIRC.