Hello, I’m creating a TCP server socket using an ethernet connection with following code:
Socket _serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_serverSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
_serverSocket.Bind(new IPEndPoint(IPAddress.Any, ServerPort));
Socket newClient = _serverSocket.Accept();
Running in debug, the thread hangs on the .Accept() method until a new client connects, which is all fine. However, when I remove the ethernet cable, the .Accept() method isn’t throwing an exception like I would expect. Instead, it just continues sleeping until the .Accept() method is either called again or the network is reestablished and a client connects.
Is there any way for me to force the .Accept method to end if the network connection is interrupted?