<<> 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 !>> But only if a tilde (#126) is included in the binary data sent, right? -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Francois PIETTE Sent: Saturday, November 18, 2006 7:26 AM To: ICS support mailing Subject: Re: [twsocket] Need example code for identifying a recordbeforeprocessing > 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
The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. If the reader of this message is not the intended recipient, you are hereby notified that your access is unauthorized, and any review, dissemination, distribution or copying of this message including any attachments is strictly prohibited. If you are not the intended recipient, please contact the sender and delete the material from any computer.
-- 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