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 MessageReadCallback() { while (true) { if (_client.Guid != Guid.Empty && MessageSocket.Connected) { try { var socketModel = SocketCommands.Read(MessageSocket); foreach (var message in socketModel.Message) { Console.WriteLine(socketModel.Name + ":" + message); } } catch (SocketException) { Exit(); } } } }
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); } } }