private void SendHistory(PipeConnection connection) { foreach (var message in messageStorage.GetMessages()) { connection.SendMessage(message.ToString()); } ; }
private void RedirectClient() { string newConnectionName = GenerateConnectionName(); PipeConnection newConnection = new PipeConnection(newConnectionName); connections.Add(newConnection); StartConnectionForClient(newConnection); // Send to client it's new connection name mainConnection.SendMessage(newConnectionName); }
private void StartConnectionForClient(PipeConnection pipeConnection) { ThreadPool.QueueUserWorkItem(state => { pipeConnection.StartConnection(); SendHistory(pipeConnection); while (true) { string input = pipeConnection.WaitMessage(); Message message = new Message { Text = input, ClientName = pipeConnection.GetClientName(), Date = DateTime.Now }; this.messageStorage.Add(message); Console.WriteLine(message.ToString()); BroadcastMessage(message.ToString()); } }); }
public Server() { connections = new ConcurrentBag <PipeConnection>(); mainConnection = new PipeConnection(mainPipeName); messageStorage = new MessageStorage(10); }