// Occures when a new client is accepted private void AcceptClient() { srReceiver = new System.IO.StreamReader(tcpClient.GetStream()); swSender = new System.IO.StreamWriter(tcpClient.GetStream()); // Read the account information from the client try { connectMsg = srReceiver.ReadLine(); } catch (Exception ex) { Log.WriteLineFail(ex.Message); } // We got a response from the client //if (connectMsg != null) if (connectMsg == "KHR-1HV") { // 1 means connected successfully swSender.WriteLine("1"); swSender.Flush(); } else { CloseConnection(); return; } try { // Keep waiting for a message from the user while ((strResponse = srReceiver.ReadLine()) != "") { if (strResponse != null) { // send the message to the users Network.OnNewMessage(strResponse); } } } catch (Exception ex) { // If anything went wrong with this user. Log.WriteLineFail(ex.Message); } }