private void DoChat() { var bytesFrom = new byte[_client.ReceiveBufferSize]; while (true) { try { var networkStream = _client.GetStream(); if (networkStream.DataAvailable) { networkStream.Read(bytesFrom, 0, _client.ReceiveBufferSize); } else { continue; } var dataFromClient = Encoding.ASCII.GetString(bytesFrom).Trim(); dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf("<EOF>", StringComparison.Ordinal)); if (dataFromClient.Equals("!c")) { ServerSocket.RemoveClient(_name, _client); break; } ServerSocket.Broadcast(dataFromClient, _name); } catch (Exception ex) { Console.WriteLine(ex.ToString()); break; } } ServerSocket.RemoveClient(_name, _client); this.thread.Abort(); }