I'm developing a server-client application. The server listens on some port (ex : 9090).
What to do if the computer is already using that port in another application? how do developers deal with it?
Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint ep = new IPEndPoint(IPAddress.Any, 9090);
server.Bind(ep);
server.Listen(100);
You immediately terminate your program with an error message that says that the port is already in use.
That's what everyone else does, too.
(Of course the port number should be configurable.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With