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?

 

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.

 

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;

 

Can I use PeekData() for this, and then, after looking under the hood, pass
the record off intact to the appropriate method? If yes, does anybody have a
code sample, or at least pseudocode for this?

 

If no, does anybody have code sample or pseudocode for how I should handle
it instead?

 

I want to be able to do something like this:

 

procedure TfClientMain.WSocket_AsServerDataAvailable(Sender: TObject;
ErrCode: Word);

const

  BLA = 1;

  BLEE = 2;

Var

  iOpCode: Integer;

begin

  if ErrCode <> 0 then begin

    ClientDM.InsertException(

      CurrentUser,

      Format(sErrorNInWSocket_AsServerDataAvailable, [ErrCode]),

      GetHostNameOrDefaultIPAddress);

    Exit;

  end;

  iOpCode := ExtractOpCode from record

  case iOpCode of

  BLA: ProcessBla(SocketData)

  BLEE: ProcessBlee(SocketData)

  . . .

end;

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

Reply via email to