Basic I/O with the INDI Server

The messages are XML, but the data is in a stream consisting of a sequence of messages. Each message can be treated independently and is self-contained. It is up to the client to organize the messages based on hints contained in the messages themselves (as provided by the device driver). This means that the first tricky part is to read a complete message and only a complete message so we can parse it.

The procedure will look like this:

  1. Initialize our buffer to an empty string.
  2. Read text from the server, appending it to our buffer.
  3. Examine the buffer to see if it is a contains an XML element that forms a complete message.
  4. If not, go back to 2.
  5. If so, pull the complete message part out of the buffer (starting at the beginning of the buffer) leaving any remaining text in the buffer.
  6. Parse the message and hand the results back to the caller.

The client program will be responsible for doing something with the parsed message. The library module does nothing but return it. The next time the method is called, it will read the next bit of text and append it to whatever (possibly nothing) was left from the previous call.