Exemple #1
0
        private void OnRecvData(IAsyncResult result)
        {
            byte[] newBytes = new byte[0];
            try
            {
                int length = stream.EndRead(result);
                if (length <= 0)
                {
                    CloseConnection();
                    return;
                }

                newBytes = new byte[length];
                Array.Copy(recvBuffer, newBytes, length);

                GameRunner.Game.handleDataQueue.Enqueue(() =>
                {
                    ServerHandleData.HandleData(connectionID, newBytes);
                });

                stream.BeginRead(recvBuffer, 0, socket.ReceiveBufferSize, OnRecvData, null);
            }
            catch (System.Exception e)
            {
                Console.WriteLine($"OnRecvData something went extremely wrong at conn id {connectionID.ToString()}");
                Console.WriteLine(e);
                CloseConnection();
                return;
            }
        }
Exemple #2
0
 public static void InitializeNetwork()
 {
     Console.WriteLine("Initialize Packets...");
     ServerHandleData.InitializePackets();
     serverSocket.Start();
     serverSocket.BeginAcceptTcpClient(new AsyncCallback(OnClientConnect), null);
 }