private static void NameReceive(DestinationClient client, UserInput value) { var name = value.Input; clients[client] = name; Console.WriteLine($"{client.RemoteEndPoint} now is {name}"); }
private static void MessageReceive(DestinationClient client, UserInput value) { var senderName = clients[client]; var message = value.Input; Console.WriteLine($"{senderName} say: {message}"); var userMassage = new UserMessage(senderName, message); foreach (var otherClient in clients) { otherClient.Key.Send((int)ScEventId.SendUserMessage, userMassage); } }
public void Group_Add_ShouldNotAddClientFromOtherServer() { var additionalServer = new FlowServer() .UsingModule(new TcpModule(LocalAddress, Port2)) .Start(); DestinationClient additionalClient = null; additionalServer.ClientConnected += c => additionalClient = c; new FlowClient(LocalAddress, Port2).Connect(); var group = new FlowGroup(server); Assert.Throws(typeof(Exception), () => group.Add(additionalClient)); }
private async void AcceptHandler() { try { while (working) { var client = await listener.AcceptTcpClientAsync(); var destinationClient = new DestinationClient(new TcpProtocol(client), owner, client.Client.RemoteEndPoint); owner.ConnectMe(destinationClient); } } catch (ObjectDisposedException exception) { if (working) { throw; } } }
private static void Server_ClientDisconnected(DestinationClient client) { Console.WriteLine($"{(clients.ContainsKey(client) ? clients[client] : client.RemoteEndPoint.ToString())} disconnected"); clients.Remove(client); }
private static void Server_ClientConnected(DestinationClient client) { Console.WriteLine($"Someone connected on {client.RemoteEndPoint}"); client.Send((int)ScEventId.SendUserMessage, new UserMessage("Server", "What is your name?")); }