private static void AcceptServiceCallback(IAsyncResult ar) { Socket socket; try { socket = ServiceSocket.EndAccept(ar); } catch (ObjectDisposedException) { return; } var clientSocket = SocketCommands.Read(socket); clientSocket.Message = _chatHistoryFixedSizedQueue.ToList(); clientSocket.Guid = Guid.NewGuid(); SocketCommands.Write(socket, clientSocket); ServiceSocket.BeginAccept(AcceptServiceCallback, null); }
private static void MessageWriteCallback() { while (true) { var socketMessage = new SocketClient { Name = _client.Name, Guid = _client.Guid, Message = new List <string>() }; socketMessage.Message.Add( MessageList.ElementAt(new Random().Next(0, MessageList.Count - 1))); try { SocketCommands.Write(MessageSocket, socketMessage); } catch (SocketException) { Exit(); } Thread.Sleep(BetweenMessagePauseTime); } }
private static void ConnectServiceCallback(IAsyncResult ar) { try { ServiceSocket.EndConnect(ar); MessageSocket.BeginConnect(IPAddress.Loopback, MessagePort, ConnectMessageCallback, null); } catch (SocketException) { Console.WriteLine("Connection was not established!"); } Console.WriteLine("ServiceSocket Connected"); SocketCommands.Write(ServiceSocket, _client); while (_client.Guid == Guid.Empty) { var socketModel = SocketCommands.Read(ServiceSocket); _client.Guid = socketModel.Guid; foreach (var message in socketModel.Message) { Console.WriteLine(message); } } }