public void Stop() { var message = new Message { MessageType = MessageType.Disconnect, SourceUsername = Username }; streamWriter.WriteLine(messageMapper.GetStringFromMessage(message)); streamWriter.Flush(); threadListen.Abort(); stream.Close(); tcpClient.Close(); }
public void Stop() { tcpListener.Stop(); threadNewConnections.Abort(); var messageDisconnect = new Message { MessageType = MessageType.Disconnect }; foreach (var listener in listeners.Values) { var clientStream = listener.TcpClient.GetStream(); var streamWriter = new StreamWriter(clientStream); streamWriter.WriteLine(messageMapper.GetStringFromMessage(messageDisconnect)); listener.Thread.Abort(); listener.TcpClient.Close(); } }