Exemple #1
0
        private void HandleKeyboardInput(Socket handler)
        {
            int received;

            byte[] sizeBuffer = new byte[4];
            byte[] buffer;

            received = handler.Receive(sizeBuffer);

            while (received > 0 || (received == 1 && sizeBuffer[0] != (byte)NetworkPacket.PacketType.EndKeyboard))
            {
                buffer = new byte[System.BitConverter.ToInt32(sizeBuffer, 0)];

                handler.Receive(buffer);

                //Network byte order is in big endian. Ensure that we recieve the data in the same way
                if (BitConverter.IsLittleEndian)
                {
                    Array.Reverse(buffer);
                }

                InputController.InputMessage(BitConverter.ToString(buffer));
            }
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="handler"></param>
        /// <returns>Whether or not the packet END_STREAM has been encountered</returns>
        private bool handleInput(Socket handler)
        {
            byte[] buffer = new byte[1];
            byte   packet;

            int numBytes = handler.Receive(buffer);

            if (numBytes > 0)
            {
                packet = buffer[0];

                String message = String.Empty;

                switch (packet)
                {
                    #region Handle Input

                case (byte)NetworkPacket.PacketType.SingleClick:
                    InputController.SingleClick();
                    message = "Single Click Received";
                    break;

                case (byte)NetworkPacket.PacketType.DoubleClick:
                    InputController.DoubleClick();
                    message = "Double Click Received";
                    break;

                case (byte)NetworkPacket.PacketType.Scroll:
                    HandleScroll(handler);
                    message = "Scroll Received";
                    break;

                case (byte)NetworkPacket.PacketType.RightClick:
                    InputController.RightClick();
                    message = "Right Click";
                    break;

                case (byte)NetworkPacket.PacketType.Disconnect:
                    message = "End Connection";
                    break;

                case (byte)NetworkPacket.PacketType.Sleep:
                    ComputerPowerOptions.Sleep();
                    message = "Sleep";
                    break;

                case (byte)NetworkPacket.PacketType.Shutdown:
                    ComputerPowerOptions.Shutdown();
                    message = "Shutdown";
                    break;

                case (byte)NetworkPacket.PacketType.Restart:
                    ComputerPowerOptions.Restart();
                    message = "Restart";
                    break;

                default:
                    message = "Unknown Data Received " + packet;
                    break;

                    #endregion
                }

#if DEBUG
                Console.WriteLine(message);
#endif

                return(packet == (byte)NetworkPacket.PacketType.Disconnect);
            }
            else
            {
                return(false);
            }
        }