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?
You should subscribe disconnect event when create a network.
When you disconnect cable, there should be an event, try to release your socket in that event?
In the ethernet tutorial there is the “NetworkController_NetworkLinkConnectedChanged” event at the very bottom. This should be invoked every time a network cable is connected or disconnected. In that function is where you would write something like “_serverSocket.Close();”
Be sure to subscribe to it with the line:
networkController.NetworkLinkConnectedChanged += NetworkController_NetworkLinkConnectedChanged;
Hey Mike, I implemented that line a while back but I’m pretty sure it’s because I wasn’t able to close and reopen the socket without it. Do you think that might be what’s causing this? Are you able to get an exception without it?
The board I’m using is SCM20260D and ethernet is connected to an RJ45 and connected via the ETH PHY pins. Hope that helps.
Just wanted to update this thread saying that I removed the line Mike was referring to and added an ethernet link ready check to the TCP listener and that seemed to fix it.