コード例 #1
0
        private void ReceiveBufferCallback(IAsyncResult result)
        {
            try
            {
                int readBytes = ClientNetworkStream.EndRead(result);

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

                byte[] newBytesRead = new byte[readBytes];
                Buffer.BlockCopy(_clientReceiveBuffer, Constants.NETWORK_STREAM_OFFSET, newBytesRead, Constants.NETWORK_STREAM_OFFSET, readBytes);

                //Handle the Data Here
                Text.WriteLine("Server is now handling data from " + Socket.Client.RemoteEndPoint, TextType.INFO);

                ServerHandleData.HandleData(ConnectionID, newBytesRead);

                ClientNetworkStream.BeginRead(_clientReceiveBuffer, Constants.NETWORK_STREAM_OFFSET, Socket.ReceiveBufferSize, ReceiveBufferCallback, null);
            }
            catch
            {
                CloseConnection();
                return;
            }
        }
コード例 #2
0
        public static void InitServer()
        {
            Text.WriteLine("Loading server ...", TextType.DEBUG);

            int start = GetTickCount();

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

            int end = GetTickCount();

            Text.WriteLine("Server loaded in {0} ms", TextType.DEBUG, end - start);
            //Start loop here in a new thread
        }