So I'm trying to program a pretty basic (console) server in C# as well as an equally simple GUI client program.
Here's the weird thing. When I use telnet to connect to my server for testing, I can freely disconnect or close out of telnet without causing any problems.
However, when I try using the GUI to connect, I get a System.Net.Sockets.SocketException if I close out of the GUI. The exception is as follows:
Unhandled Exception: System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.Receive(Byte[] buffer) at F_2_fish_Communicator_Server.Server.listenForInput(Object sender) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, C ontextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart(Object obj)...So naturally I try to fix this problem using a try/catch statement. After telling it to catch a SocketException didn't work, I changed it to catch any Exception, and it still doesn't seem to do so.
int length = -1; try { length = fromClient.Receive(sData); } catch (Exception e) { Console.WriteLine("Exception: {0}", e.ToString()); } thisLine += Encoding.ASCII.GetString(sData, 0, length);
Again, this exception ONLY occurs when using the GUI client to connect; telnet does not cause the "catch" block to execute or anything of the sort.
Any ideas as to why this is happening and/or how to fix it are greatly appreciated.