public static void InitializeNetwork(int port) { //Console.WriteLine("Initializing Packets"); Global.LogManager.LogInfo(message: "Initializing Packets", type: typeof(Server)); ServerHandler.InitializePackets(); serverSocket = new TcpListener(IPAddress.Any, port); serverSocket.Start(); serverSocket.BeginAcceptTcpClient(new AsyncCallback(OnClientConnect), null); //Console.WriteLine("Server Started on {0}", serverSocket.LocalEndpoint); Global.LogManager.LogInfo(message: $"Server Started on {serverSocket.LocalEndpoint}", type: typeof(Server)); }
private void OnReceiveData(IAsyncResult asyncResult) { try { int length = stream.EndRead(asyncResult); if (length <= 0) { CloseConnection(); return; } byte[] newBytes = new byte[length]; Array.Copy(receiveBuffer, newBytes, length); ServerHandler.HandleData(connectionID, newBytes); stream.BeginRead(receiveBuffer, 0, socket.ReceiveBufferSize, OnReceiveData, null); } catch (Exception) { CloseConnection(); return; } }