Index: misc/client.py
===================================================================
--- misc/client.py	(revision 3)
+++ misc/client.py	(revision 6)
@@ -1,4 +1,5 @@
 #!/usr/bin/env python
 
+import sys
 import cmd
 import struct
@@ -42,5 +43,5 @@
         self.use_rawinput = True
         self.intro = "\nX-Plane Remote Access plugin command prompt\n"
-        self.prompt = "XPLRA>"
+        self.prompt = "XPLRA> "
 
         self.daemon = True
@@ -50,5 +51,5 @@
         if line=="EOF":
             print
-            return self.do_quit("")
+            return True
         else:
             return super(CLI, self).default(line)
@@ -58,5 +59,5 @@
         words = args.split()
         if len(words)<2:
-            print >> sys.stderr, "missing parameters"
+            print >> sys.stderr, "Missing parameters"
             return False
 
@@ -65,10 +66,12 @@
         type = words[1]
         if type not in self._types:
-            print >> sys.stderr, "invalid type"
+            print >> sys.stderr, "Invalid type"
             return False
 
         length = None
-        if len(words)>2:
+        offset = None
+        if len(words)>3:
             length = int(words[2])
+            offset = int(words[3])
 
         self._writeU8(0x01)
@@ -77,9 +80,10 @@
         if length is not None:
             self._writeS32(length)
+            self._writeS32(offset)
         self._flush()
 
         result = self._readU8()
-        print "result:", result
         if result==0:
+            value = None
             if type=="i":
                 value = self._readS32()
@@ -92,12 +96,8 @@
                 if length>0:
                     value = [self._readFloat() for i in range(0, length)]
-                else:
-                    value = None
             elif type=="ia":
                 length = self._readS32()
                 if length>0:
                     value = [self._readS32() for i in range(0, length)]
-                else:
-                    value = None
             elif type=="ba":
                 length = self._readS32()
@@ -108,8 +108,9 @@
                         if b==0: break
                         value += chr(b)
-                else:
-                    value = None
+                    #value = bytes
 
-            print "value:", value, len(value)
+            print value
+        else:
+            print "Result code:", result
 
     def _writeU8(self, x):
Index: misc/test1.sh
===================================================================
--- misc/test1.sh	(revision 6)
+++ misc/test1.sh	(revision 6)
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+scriptdir=`dirname $0`
+
+"${scriptdir}/client.py" <<EOF
+get sim/aircraft/engine/num_engines i
+get sim/aircraft/engine/acf_num_engines i
+get sim/aircraft/engine/acf_auto_featherEQ i
+get sim/aircraft/engine/acf_spooltime_jet f
+get sim/aircraft/engine/acf_spooltime_prop f
+get sim/flightmodel/position/latitude d
+get sim/flightmodel/position/longitude d
+get sim/aircraft/view/acf_descrip ba -1 0
+get sim/aircraft/prop/acf_en_type ia -1 0
+get sim/aircraft/prop/acf_prop_dir fa -1 0
+EOF
Index: src/xplra/DataRefTask.h
===================================================================
--- src/xplra/DataRefTask.h	(revision 3)
+++ src/xplra/DataRefTask.h	(revision 6)
@@ -72,4 +72,5 @@
     DataRefTask(XPLMDataRef dataRef);
 
+public:
     /**
      * Determine if the task is valid, which is so, if the dataref is
@@ -88,4 +89,5 @@
     XPLMDataRef getDataRef() const;
 
+protected:
     /**
      * Perform the task. If the dataref is not valid yet, it will be
Index: src/xplra/GetDataRefTask.cc
===================================================================
--- src/xplra/GetDataRefTask.cc	(revision 4)
+++ src/xplra/GetDataRefTask.cc	(revision 6)
@@ -30,4 +30,5 @@
 
 #include "GetDataRefTask.h"
+#include "Protocol.h"
 
 #include "xplcommon/Util.h"
@@ -35,4 +36,71 @@
 //------------------------------------------------------------------------------
 
+using xplra::GetDataRefTask;
+using xplra::GetIntDataRefTask;
+using xplra::GetFloatDataRefTask;
+using xplra::GetDoubleDataRefTask;
+
+using xplcommon::DataStream;
+
+using std::string;
+
+//------------------------------------------------------------------------------
+
+GetDataRefTask* GetDataRefTask::create(uint8_t& result, DataStream& stream)
+{
+    result = Protocol::RESULT_OK;
+
+    string name = stream.readString();
+    uint8_t type = stream.readU8();
+    if (!stream) return 0;
+
+    if (type==Protocol::TYPE_INT) {
+        return new GetIntDataRefTask(name);
+    } else if (type==Protocol::TYPE_FLOAT) {
+        return new GetFloatDataRefTask(name);
+    } else if (type==Protocol::TYPE_DOUBLE) {
+        return new GetDoubleDataRefTask(name);
+    } else if (type==Protocol::TYPE_FLOAT_ARRAY ||
+               type==Protocol::TYPE_INT_ARRAY ||
+               type==Protocol::TYPE_BYTE_ARRAY)
+    {
+        int length = stream.readS32();
+        int offset = stream.readS32();
+        if (!stream) return 0;
+
+        if (type==Protocol::TYPE_FLOAT_ARRAY) {
+            return new GetFloatArrayDataRefTask(name, length, offset);
+        } else if (type==Protocol::TYPE_INT_ARRAY) {
+            return new GetIntArrayDataRefTask(name, length, offset);
+        } else {
+            return new GetByteArrayDataRefTask(name, length, offset);
+        }
+    } else {
+        result = Protocol::RESULT_INVALID_TYPE;
+        return 0;
+    }
+}
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+void GetIntDataRefTask::writeValue(DataStream& stream)
+{
+    stream.writeS32(getValue());
+}
+
+//------------------------------------------------------------------------------
+
+void GetFloatDataRefTask::writeValue(DataStream& stream)
+{
+    stream.writeFloat(getValue());
+}
+
+//------------------------------------------------------------------------------
+
+void GetDoubleDataRefTask::writeValue(DataStream& stream)
+{
+    stream.writeDouble(getValue());
+}
 
 //------------------------------------------------------------------------------
Index: src/xplra/GetDataRefTask.h
===================================================================
--- src/xplra/GetDataRefTask.h	(revision 4)
+++ src/xplra/GetDataRefTask.h	(revision 6)
@@ -33,4 +33,6 @@
 #include "DataRefTask.h"
 
+#include <xplcommon/DataStream.h>
+
 //------------------------------------------------------------------------------
 
@@ -46,4 +48,14 @@
 public:
     /**
+     * Read a dataref query specification and create the appropriate
+     * GetDataRefTask instance.
+     *
+     * @return the new instance, or 0 on error. In that case the given
+     * result reference variable will be filled with the error code,
+     * unless the stream failed, in which case it remains RESULT_OK.
+     */
+    static GetDataRefTask* create(uint8_t& result, xplcommon::DataStream& stream);
+
+    /**
      * Construct the task for the dataref with the given name.
      */
@@ -54,4 +66,9 @@
      */
     GetDataRefTask(XPLMDataRef dataRef);
+
+    /**
+     * Write the value into the given stream.
+     */
+    virtual void writeValue(xplcommon::DataStream& stream) = 0;
 };
 
@@ -120,4 +137,9 @@
      */
     GetIntDataRefTask(XPLMDataRef dataRef);
+
+    /**
+     * Write the value into the given stream.
+     */
+    virtual void writeValue(xplcommon::DataStream& stream);
 };
 
@@ -147,4 +169,9 @@
      */
     GetFloatDataRefTask(XPLMDataRef dataRef);
+
+    /**
+     * Write the value into the given stream.
+     */
+    virtual void writeValue(xplcommon::DataStream& stream);
 };
 
@@ -174,4 +201,9 @@
      */
     GetDoubleDataRefTask(XPLMDataRef dataRef);
+
+    /**
+     * Write the value into the given stream.
+     */
+    virtual void writeValue(xplcommon::DataStream& stream);
 };
 
@@ -253,4 +285,9 @@
      */
     virtual void process();
+
+    /**
+     * Write the value into the given stream.
+     */
+    virtual void writeValue(xplcommon::DataStream& stream);
 };
 
@@ -493,4 +530,16 @@
 
 //------------------------------------------------------------------------------
+
+template <typename T, class ConcreteClass>
+void GetArrayDataRefTask<T, ConcreteClass>::
+writeValue(xplcommon::DataStream& stream)
+{
+    stream.writeS32(length);
+    if (length>0) {
+        stream.write(data, length * sizeof(T));
+    }
+}
+
+//------------------------------------------------------------------------------
 // Inline definitions
 //------------------------------------------------------------------------------
Index: src/xplra/Makefile.am
===================================================================
--- src/xplra/Makefile.am	(revision 5)
+++ src/xplra/Makefile.am	(revision 6)
@@ -29,5 +29,6 @@
 	ServerThread.cc		\
 	TaskRequest.cc		\
-	DataRefTask.cc
+	DataRefTask.cc		\
+	GetDataRefTask.cc
 
 libxplra_la_LIBADD=$(LIBXPLCOMMON_LIBS)
Index: src/xplra/Protocol.h
===================================================================
--- src/xplra/Protocol.h	(revision 5)
+++ src/xplra/Protocol.h	(revision 6)
@@ -44,5 +44,5 @@
      * Command: get the value of a single dataref.
      */
-    static const uint8_t CMD_GET_SINGLE = 0x01;
+    static const uint8_t COMMAND_GET_SINGLE = 0x01;
 
     /**
Index: src/xplra/ServerThread.cc
===================================================================
--- src/xplra/ServerThread.cc	(revision 5)
+++ src/xplra/ServerThread.cc	(revision 6)
@@ -110,35 +110,6 @@
         //             this, command);
 
-        if (command==Protocol::CMD_GET_SINGLE) {
-            string name = stream.readString();
-            uint8_t type = stream.readU8();
-            if (!stream) continue;
-            // Util::debug("hu.varadiistvan.xplra.ServerThread[%p]::run: name='%s', type=0x%02x\n",
-            //             this, name.c_str(), type);
-            if (type==Protocol::TYPE_BYTE_ARRAY) {
-                int length = stream.readS32();
-                if (!stream) continue;
-
-                // Util::debug("hu.varadiistvan.xplra.ServerThread[%p]::run: length=%lu\n",
-                //             this, static_cast<unsigned long>(length));
-
-                GetByteArrayDataRefTask* task =
-                    new GetByteArrayDataRefTask(name, length);
-                TaskRequest request(task);
-
-                if (requestQueue.execute(&request)) {
-                    // Util::debug("hu.varadiistvan.xplra.ServerThread[%p]::run: request executed\n");
-                    stream.writeU8(Protocol::RESULT_OK);
-                    int length = task->getLength();
-                    stream.writeS32(length);
-                    if (length>0) {
-                        stream.write(task->getData(), length);
-                    }
-                } else {
-                    break;
-                }
-            } else {
-                stream.writeU8(Protocol::RESULT_OTHER_ERROR);
-            }
+        if (command==Protocol::COMMAND_GET_SINGLE) {
+            if (!handleGetSingle(stream)) break;
         } else {
             stream.writeU8(Protocol::RESULT_INVALID_COMMAND);
@@ -152,4 +123,31 @@
 //------------------------------------------------------------------------------
 
+bool ServerThread::handleGetSingle(xplcommon::DataStream& stream)
+{
+    uint8_t result = Protocol::RESULT_OK;
+
+    GetDataRefTask* task = GetDataRefTask::create(result, stream);
+
+    if (!stream) return false;
+    else if (task==0) {
+        stream.writeU8(Protocol::RESULT_INVALID_TYPE);
+        return true;
+    }
+
+    TaskRequest request(task);
+    if (!requestQueue.execute(&request)) return false;
+
+    if (task->isValid()) {
+        stream.writeU8(Protocol::RESULT_OK);
+        task->writeValue(stream);
+    } else {
+        stream.writeU8(Protocol::RESULT_UNKNOWN_DATAREF);
+    }
+
+    return true;
+}
+
+//------------------------------------------------------------------------------
+
 // Local Variables:
 // mode: C++
Index: src/xplra/ServerThread.h
===================================================================
--- src/xplra/ServerThread.h	(revision 5)
+++ src/xplra/ServerThread.h	(revision 6)
@@ -122,4 +122,12 @@
      */
     virtual void run();
+
+private:
+    /**
+     * Handle the COMMAND_GET_SINGLE command
+     *
+     * @return true, if we can continue, false if the thread should quit
+     */
+    bool handleGetSingle(xplcommon::DataStream& stream);
 };
 
