Eric,

you asked on Thu, 29 Jan 2004 15:16:56 -0800:
> Hi all, maybe someone has run into this problem before:
> I have a program that uses the following code:
> Several arrays (numeric) are flattened to strings, then the strings are
> concatenated (with a delimiter between each string) before it is sent 
> to a TCP write function. On the other end, I parse the TCP read string
> using the match pattern with the delimiter being the same as the write
> side (currently a tab constant). Pretty basic, and works fine most of
> the time. However, it seems that sometimes a tab shows up as part of the
> flattened string, and confuses the match pattern into thinking this is
> the delimiter. This causes all kinds of havoc with the program.
> Is this a possible situation?
> Does anyone know of a good delimiter that is not one of the flattened
> string characters (if it exists)?
> Thanks in advance,=20
> Eric Scott


Christian Altenbach  <[EMAIL PROTECTED]> answered
> Eric,
> 
> Your problem has really nothing to do with TCP per se.
> Instead of a delimiter, prepend each flattened substring with its flattened
> string lenght before concatenating them.
> When you unflatten, just clip the first 4 chars of the string, unflatten to
> I32, then clip a string with that lenght, clip another I32, and so on.
> If the strings are shorter than 256, you could use an U8 for length.

There is another possibel aproach that does a transparent exchange of your
delimiter chars in the original data with some extra code.
This may be faster ore more code effective than Christians aproach, but as
always. It depends...

How to do it?
You define an escape character (maybe really <Esc>=0x1B or even better a
char that is unlikely to show up in your data). Than replace any occurance
of this char in your original data with a sequence of <escape><0x1> and
afterwards all occurances of <delimiter with <escape><0x2>. Send this data
and perform the inverse operation before using your delimiter.
Both transcodings can be transparent. 
I do not have VIs at hand, but exactly this is what is done when
transfering our medical measurements between different 'nodes' (may those
be instances of operational units, devices or even machines).

A side note:
You should test a set of your raw data and do a histogram of all chars
therein. Use the two chars that do show up least often as <escape> and as
<delimiter>.

Greetings from Germany!
-- 
Uwe Frenz


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dr. Uwe Frenz
Entwicklung
getemed Medizin- und Informationtechnik AG
Oderstr. 59
D-14513 Teltow

Tel.  +49 3328 39 42 0
Fax   +49 3328 39 42 99
[EMAIL PROTECTED]
WWW.Getemed.de


Reply via email to