   Chat tutorial help please (C#)
  I've been going through those two tutorials:http://www.geekpedia.com/tutorial239_Csharp-Chat-Part-1---Building-the-Chat-Client.htmlhttp://www.geekpedia.com/tutorial240_Csharp-Chat-Part-2---Building-the-Chat-Server.htmlI've got the client and server up and running.  However, when the client disconnects, it throws an exception.  There's also no way to end the server once it's running.  This is my first networking attempt, and I tried adding this code to server when the application closes:public void StopListening(){ServRunning = false;if (thrListener != null){thrListener.Abort();}TcpClient[] tcpClients = new TcpClient[htUsers.Count];htUsers.Values.CopyTo(tcpClients, 0);foreach (TcpClient t in tcpClients){RemoveUser(t);}if (tlsClient != null){tlsClient.Stop();}}It don't quite work in that it actually stop the server, and the clients don't have anything to handle the fact that server is ending.  So both server and client throw exception after client disconnects, instead of just the client throwing an exception.Other people in comments area seem to be having the same problems, however nobody've posted solutions to those problems.  If you could help me out in this, I'd appreciate it!   
  I'm going to have to look into .Net specific networking some time...Quote:when the client disconnects, it throws an exceptionWhich one?Quote:There's also no way to end the server once it's runningThere's always task manager...First, mark the ServRunning variable as volatile.public void StopListening() {  ServRunning = false;  tlsClient.Stop();  // nudge the KeepListening  // killing threads is generally considered undesirable, join instead  if (thrListener != null) thrListener.Join();   // no new connections should be accepted from this point on  foreach (TcpClient t in tcpClients) {    RemoveUser(t);    try { t.close(); // doesn't seem like connections are being closed in RemoveUser  // should probably be part of RemoveUser    } catch (WhateverMustBeCaught ...) { // something, not much can be done    }  }}But despite several threads being used there doesn't seem to be any synchronization being done in the original code.There is also distinct lack of error handling, or even lack of any kind of try/catch statements.   ;  Creating a new set of TCP clients makes no sense whatsoever.;  I know the tutorial had some bugs, but I didn't know it was that bad.  I was trying to find some decent tutorials on C# and networking, especially for a simple chat application.How do I know if a tutorial's good?  This is a new area for me.  I thought this was a good tutorial because it actually worked, although with some bugs.So a server should only have one client?  What modifications to the code will it require to accomplish that?   ;  I'd check Lidgren Network library. Among other samples, it contains a chat client and chat server:http://code.google.com/p/lidgren-network-gen3/It is open source so you can learn a lot by reading proper network code and modifying it as you wish. It is reliable UDP though, not sure if that matters to you.   