Esempio n. 1
0
 private void OnReceiveData(IAsyncResult result)
 {
     try{
         int readbytes = myStream.EndRead(result);
         if (readbytes <= 0)
         {
             //client is not connected to the server anymore
             CloseSocket();
             return;
         }
         byte[] newBytes = new byte[readbytes];
         Buffer.BlockCopy(readBuff, 0, newBytes, 0, readbytes);
         ServerHandleData.HandleData(connectionID, newBytes);
         myStream.BeginRead(readBuff, 0, socket.ReceiveBufferSize, OnReceiveData, null);
     }
     catch (Exception)
     {
         CloseSocket();
     }
 }
Esempio n. 2
0
        public static void InitializeServer()
        {
            int startTime = 0; int endTime = 0;

            startTime = GetTickCount();
            Logger.WriteDebug("Initializing Server...");
            //Intializing all game data arrays
            Logger.WriteDebug("Initializing Game Arrays...");
            for (int i = 0; i < Constants.MAX_PLAYERS; i++)
            {
                ServerTCP.Client[i] = new Clients();
            }

            //Start the Networking
            Logger.WriteDebug("Initializing Network...");
            ServerHandleData.InitializePackets();
            ServerTCP.InitializeNetwork();

            endTime = GetTickCount();
            Logger.WriteInfo("Initialization complete. Server loaded in " + (endTime - startTime) + " ms.");
        }