How To Read Data With Synapse

There does not exist an event for reading data in Synpase. Why? It is not needed! In other libraries you must read data when it comes in to your system with an event. This event is outside of your processing procedure! Then you must parse this data and get what you need! You must synchronise your procedure with these events. It is not practical in most cases!

Synapse is a synchronous library, because you do not need to do this synchronisation. All data read is synchronised with your processing code! You do not need to know when data arrives. This data is silently stored in internal buffers.

You call a read operation when you need read some data. Look, you call read operation when YOU need data, not when the system needs to read data!

When you need to read data, then you need to:

  • read known count of bytes
  • read byte with known terminator
  • read any data
  • combination of above

1. read known count of bytes

You know how many bytes you need. You can use RecvBuffEx method to receive a specific number of bytes in to your binary buffer. You can use RecvBuffStr too. This function reads bytes in to a binary string. This string is good for a dynamicly allocated binary buffer. (see to another article)

2. read byte with known terminator

You know the sequence which terminates your data block. You can use the RecvTerminated method. A special case is reading lines of text terminated by CRLF. For this you can use special RecvString method. When you use this method and turn on the ConvertLineEnd property, then Synapse autodetects the correct line terminating sequence. It can receive lines terminated by CRLF, LFCR, CR or LF! It is very good for your bug-tolerant application.

3. read any data

You simply need to receive any incoming data, regardless of the amount. Then you can use the RecvPacket method.

4. combination of above

You can freely combine all the previous methods. You can read one line with length (in text form) of next data block and then you can read this data block with RecvBuffStr, for example.

public/howto/readdata.txt · Last modified: 2007/11/30 14:30 (external edit)
Driven by DokuWiki Recent changes RSS feed