Beispiel #1
0
        protected string SendCommand(string command)
        {
            string result = string.Empty;

            lock (ClientSocket)
            {
                if (!ClientSocket.Connected)
                {
                    Connect();
                }
                if (ClientSocket.Connected)
                {
                    RequestPacket  reqPacket  = NewRequest(RequestPacketType.COMMAND, command);
                    ResponsePacket respPacket = SendRequest(reqPacket);
                    result = respPacket.Data;
                }
                else
                {
                    throw new ApplicationException("You must be connected to send a command!");
                }
            }
            return(result);
        }
Beispiel #2
0
        protected bool Authenticate()
        {
            bool isAuthenticated = false;

            lock (ClientSocket)
            {
                if (ClientSocket.Connected)
                {
                    RequestPacket  reqPacket  = NewRequest(RequestPacketType.AUTH, SecureUtils.GetSecureStringValue(_password));
                    ResponsePacket respPacket = SendRequest(reqPacket);

                    if (respPacket.PacketId != -1)
                    {
                        isAuthenticated = true;
                    }
                }
                else
                {
                    throw new ApplicationException("You must be connected before you can authenticate!");
                }
            }
            return(isAuthenticated);
        }
Beispiel #3
0
        protected ResponsePacket SendRequest(RequestPacket requestPacket)
        {
            ResponsePacket result;
            lock (ClientSocket)
            {
                byte[] sendPacket = requestPacket.GetBytes();
                int bytesSent = ClientSocket.Send(sendPacket);

                byte[] bytesReceived = new byte[4096];
                int bytesReceiveSize = ClientSocket.Receive(bytesReceived);

                result = new ResponsePacket(bytesReceived, requestPacket);
            }
            return result;
        }