Пример #1
0
        private void ReceiverBufferCallback(IAsyncResult ar)
        {
            try
            {
                int readBytes = myStream.EndRead(ar);

                if (readBytes <= 0)
                {
                    CloseConnection();
                    return;
                }

                byte[] newBytes = new byte[readBytes];
                Buffer.BlockCopy(recBuffer, 0, newBytes, 0, readBytes);

                // Handle data here
                ServerHandleData.HandleData(connectionId, newBytes);

                myStream.BeginRead(recBuffer, 0, this.socket.ReceiveBufferSize, ReceiverBufferCallback, null);
            }
            catch
            {
                CloseConnection();
                return;
            }
        }
Пример #2
0
        public static void InitServer()
        {
            isRunning = true;

            Logger.WriteLine("Loading server ...", LogLevel.DEBUG);

            int start = GetTickCount();

            InitClients();
            ServerHandleData.InitPackets();
            ServerTCP.InitServer();

            int end = GetTickCount();

            Logger.WriteLine("Server has been loaded in {0}ms", LogLevel.DEBUG, end - start);

            // Start Loop here in a new thread
        }