ProcessCommand() public method

public ProcessCommand ( RemoteCommand cmd ) : void
cmd RemoteCommand
return void
Beispiel #1
0
        // This processes the client.
        // Returns false when the connection was closed.
        public bool Process(RemoteManager manager)
        {
            // Send data
            int          maxsendbytes   = Math.Min(SEND_RECEIVE_SIZE, (int)sendbuffer.Length);
            int          bytessent      = socket.Send(sendbuffer.ToArray(), 0, maxsendbytes, SocketFlags.None);
            int          bytesremaining = (int)sendbuffer.Length - bytessent;
            MemoryStream oldbuffer      = sendbuffer;

            sendbuffer = new MemoryStream(Math.Max(bytesremaining, SEND_RECEIVE_SIZE));
            if (bytesremaining > 0)
            {
                sendbuffer.Write(oldbuffer.ToArray(), bytessent, bytesremaining);
            }
            oldbuffer.Dispose();

            // Receive data
            byte[] datablock     = new byte[SEND_RECEIVE_SIZE];
            int    bytesreceived = socket.Receive(datablock);

            if (bytesreceived == 0)
            {
                // When Receive returns 0 bytes the connection was closed
                return(false);
            }
            else
            {
                // Receive new data from client
                NotifyResponse();
                ReceiveData(datablock, bytesreceived);

                // Parse and process commands
                RemoteCommand c = TryParseCommand();
                while (c != null)
                {
                    manager.ProcessCommand(c);
                    c = TryParseCommand();
                }

                return(true);
            }
        }
Beispiel #2
0
        // This processes the client.
        // Returns false when the connection was closed.
        public bool Process(RemoteManager manager)
        {
            // Send data
            int maxsendbytes = Math.Min(SEND_RECEIVE_SIZE, (int)sendbuffer.Length);
            int bytessent = socket.Send(sendbuffer.ToArray(), 0, maxsendbytes, SocketFlags.None);
            int bytesremaining = (int)sendbuffer.Length - bytessent;
            MemoryStream oldbuffer = sendbuffer;
            sendbuffer = new MemoryStream(Math.Max(bytesremaining, SEND_RECEIVE_SIZE));
            if(bytesremaining > 0)
                sendbuffer.Write(oldbuffer.ToArray(), bytessent, bytesremaining);
            oldbuffer.Dispose();

            // Receive data
            byte[] datablock = new byte[SEND_RECEIVE_SIZE];
            int bytesreceived = socket.Receive(datablock);
            if(bytesreceived == 0)
            {
                // When Receive returns 0 bytes the connection was closed
                return false;
            }
            else
            {
                // Receive new data from client
                NotifyResponse();
                ReceiveData(datablock, bytesreceived);

                // Parse and process commands
                RemoteCommand c = TryParseCommand();
                while(c != null)
                {
                    manager.ProcessCommand(c);
                    c = TryParseCommand();
                }

                return true;
            }
        }