Example #1
0
 public GameClient(string address, int port)
 {
     _udp = new UdpClient(0)
     {
         Client = { Blocking = false }
     };
     _target = new IPEndPoint(IPAddress.Parse(address), port);
     _server = new NetworkConnection(_udp, _target);
     _server.MessageReceived    += (fromAddr, message) => MessageReceived?.Invoke(fromAddr, message);
     _server.ClientDisconnected += (fromAddr) => ServerDisconnected?.Invoke(fromAddr);
     _server.MessageAcked       += (fromAddr, message) => MessageAcked?.Invoke(fromAddr, message);
     _server.MessageLost        += (fromAddr, message) => MessageLost?.Invoke(fromAddr, message);
     _reliable = new ReliableConnection(_server);
     _reliable.ReliableMessageRecieved += (fromAddr, message) => ReliableMessageReceived?.Invoke(fromAddr, message);
 }
Example #2
0
 private void HandleNewClientConnection(IPEndPoint clientAddr)
 {
     _clients[clientAddr] = new NetworkConnection(_udp, clientAddr);
     _clients[clientAddr].MessageReceived    += (fromAddr, message) => MessageReceived?.Invoke(fromAddr, message);
     _clients[clientAddr].ClientDisconnected += (fromAddr) =>
     {
         _clients.Remove(fromAddr);
         _reliableClients.Remove(fromAddr);
         ClientDisconnected?.Invoke(fromAddr);
     };
     _clients[clientAddr].MessageAcked += (fromAddr, message) => MessageAcked?.Invoke(fromAddr, message);
     _clients[clientAddr].MessageLost  += (fromAddr, message) => MessageLost?.Invoke(fromAddr, message);
     _reliableClients[clientAddr]       = new ReliableConnection(_clients[clientAddr]);
     _reliableClients[clientAddr].ReliableMessageRecieved += (fromAddr, message) => ReliableMessageReceived?.Invoke(fromAddr, message);
     ClientConnected?.Invoke(clientAddr);
 }