Esempio n. 1
0
		public ResponsePacket(byte[] responseData, RequestPacket requestPacket)
		{
			RequestPacket = requestPacket;

			switch (requestPacket.RequestType)
			{
				case RequestPacketType.AUTH:
					ResponseType = ResponsePacketType.AUTH_RESPONSE;
					break;
				case RequestPacketType.COMMAND:
					ResponseType = ResponsePacketType.RESPONSE_VALUE;
					break;
				default:
					ResponseType = ResponsePacketType.NONE;
					break;
			}

			ArrayList dataCache;
			// Start at 4
			int pos = 4;
			// Read the Packet ID
			PacketId = BitConverter.ToInt32(responseData, pos);
			pos += 4;
			// Read the Response Type
			ResponseType = (ResponsePacketType)BitConverter.ToInt32(responseData, pos);
			pos += 4;
			// Read the first result string
			dataCache = new ArrayList();
			while (responseData[pos] != 0)
			{
				dataCache.Add(responseData[pos]);
				pos++;
			}
			DataString1 = utf8.GetString((byte[])dataCache.ToArray(typeof(byte)));
			pos++;
			// Read the second result string
			dataCache = new ArrayList();
			while (responseData[pos] != 0)
			{
				dataCache.Add(responseData[pos]);
				pos++;
			}
			DataString2 = utf8.GetString((byte[])dataCache.ToArray(typeof(byte)));
			pos++;
		}
Esempio n. 2
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;
        }
Esempio n. 3
0
 protected RequestPacket NewRequest(RequestPacketType type, string data1, string data2 = "")
 {
     RequestPacket requestPacket = new RequestPacket(PacketId++, type, data1, data2);
     return requestPacket;
 }
Esempio n. 4
0
        protected RequestPacket NewRequest(RequestPacketType type, string data1, string data2 = "")
        {
            RequestPacket requestPacket = new RequestPacket(PacketId++, type, data1, data2);

            return(requestPacket);
        }