> All of the records have as their first member an Integer named OpCode 
> which
> identifies itself as to which type of record it is, such as:
>  PInductionComplete = ^TInductionComplete;
>  TInductionComplete = packed record
>    OpCode: Integer;
>    Sort: Integer;
>    CarrierCount: Integer;
>    GreenLightMilliseconds: Integer;
>    OccupiedTrays: Integer;
>    RecordTerminator: Char; //This is the #126, or tilde/~ char
>  end;

>I will be receiving a variety of structs/records, all of different sizes 
>and
> "makeups".
>
> How can I (in the OnDataAvailable() handler, I assume), determine/identify
> which record has just come in, so that I can process it accordingly?

Just check the OpCode record member which tells what record type you have.
If you have received the record, or part of the record (be sure to have 
received at least 4 bytes since your OpCode is an integer) into a buffer, 
cats the buffer address to a pointer to an integer and grab your OpCode. 
Somethinhg like that:

MyOpCode := PInteger(@Buffer)^;


> OnDataAvailable() should only fire once for each record, because I am 
> having
> the sender add a #126 (~) as the last byte of each record, and using
> LineMode with LineEnd = #126.

WARNING: Since your record contains binary data, it could contains a #126 as 
part of the data. So the line mode will not work as you expect !

You have to make sure your record doesn't contain your termination 
character. You can use an "escape" mechanism for that purpose. You scan all 
the bytes in your data for the delimiter and replace it by another byte. 
Since this byte may as well be in the data, you must also substitute it. 
This result as having your delimiter (#126) replaced by TWO bytes: an escape 
character (anything you like but not #126. Let's say it is #127) and #1 (for 
example); and your escape character is replace by TWO of them. When you 
received data, you do the reverse processing: replace #127#1 by #126 and 
#127#127 by a single #127.

Alternatively, you may send your data in text form instead of binary form. 
It takes more space but you have no problem with line end terminator (The 
default CRLF is perfect) and you avoid problem with binary representation of 
data which DIFFER from one processor to another processor.

--
Contribute to the SSL Effort. Visit http://www.overbyte.be/eng/ssl.html
--
[EMAIL PROTECTED]
http://www.overbyte.be


-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to