My server app runs perfectly fine until I try to close it. At that point i'm getting two exceptions. I put in a try-catch to try and debug them, and go the following:
The first exception is: A blocking operation was interrupted by a call to WSACancelBlockingCall
and the 2nd one is Not listening. You must call the Start() method before calling this method.
Here's a snippet from where the exception occurs:
private void ListenForClients()
{
this.tcpListener.Start();
while (true)
{
try
{
TcpClient client = this.tcpListener.AcceptTcpClient(); // EXCEPTION OCCURS HERE
string clientIPAddress = "" + IPAddress.Parse(((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString());
ClientIPLabel.Text = clientIPAddress;
Thread clientThread = new Thread(new ParameterizedThreadStart(HandleClientComm));
clientThread.Start(client);
}
catch (Exception e)
{
MessageBox.Show(e.Message.ToString());
}
}
}
I'm not sure if it might be because I'm missing something here or not, but here's my code for closing the server app:
private void ShutdownServer_Click(object sender, EventArgs e)
{
this.tcpListener.Stop();
Application.Exit();
}
I'm also unable to run this app from a release build; it just freezes as soon as I try to run it, and I need to restart my machine in order to close it (I can close the form, but the process stays running in task manager and "end task" doesn't close it). I'm assuming these exceptions are likely what's causing that issue, since I can run the debug build just fine.