protected NetworkInterface(UDPConnection udpConnection, Logger logger) { Logger = logger; ClientConnections = new NetworkConnectionPool(); In = new NetworkInput(ClientConnections); Out = new NetworkOutput(ClientConnections); ErrorHandling = new NetworkErrorHandling(ClientConnections, this); UdpConnection = udpConnection; UdpConnection.Logger = logger; UdpConnection.OnReceiveError += ErrorHandling.HandleUDPReceiveError; UdpConnection.OnSendError += ErrorHandling.HandleUDPSendError; UdpConnection.InitializeReceiving(); KeepAliveInterval = 1000; m_keepAlive = true; HolePunchingInterval = 1000; m_holePunching = false; Thread keepAliveThread = new Thread(KeepAliveLoop); keepAliveThread.Name = "Keep alive"; keepAliveThread.Start(); }
static void proGamerClient() { IPEndPoint server = new IPEndPoint(IPAddress.Parse("127.0.0.1"), NetworkConstants.SERVER_PORT); Socket connectionSocket = new Socket(server.AddressFamily, SocketType.Stream, ProtocolType.Tcp); connectionSocket.Connect(server); TCPPacketConnection conn = new TCPPacketConnection(connectionSocket); connections.Add(conn); open8PlayersGame(conn); NetworkConnection networkConn = new NetworkConnection(conn); UDPConnection c = new UDPConnection(conn.Local); c.InitializeReceiving(); networkConn.SetUDPConnection(c); List <int> playerIDs = new List <int>(); while (true) { PackageInterface p = networkConn.ReadTCP(); if (p != null && p.PackageType == PackageType.ServerPlayerIDResponse) { ServerInitializeGameResponse ps = p as ServerInitializeGameResponse; foreach (Player pl in ps.m_players) { if (pl.Controllable) { playerIDs.Add(pl.ID); } } break; } else { Thread.Sleep(100); } } while (true) { foreach (int playerID in playerIDs) { sendMovementToMatchBall(networkConn, playerID); } Thread.Sleep(100); } }
public void Initialize(bool active) { udpConnection.Logger = Logger; tcpConnetion.Logger = Logger; if (!udpConnection.InitializeCrypto(new ECCrypto(active))) { tcpConnetion.Disconnect(); return; } if (!tcpConnetion.InitializeCrypto(new ECCrypto(active))) { return; } tcpConnetion.InitializeReceiving(); udpConnection.InitializeReceiving(); }