Example Source of Reliable TCP Packets with Headers and Data, OOP.
Posted on 2004-08-30
I need some good example code that deals with TCP packets where there is a known header with data length as part of the header (including header) and data.
Would like it to be asyncronous if possible. I need to be able to send data from a memo line and stuff. Perhaps an OnPacket event or something that gets called where there is a full packet available.
Anyway, this is what I am working with.
(BYTE) StartPacket - always 0xFF
(BYTE) Packet ID
(WORD) Packet length, including this header
(VOID) Packet Data
I did get something sort of working with using Indy Client, but it gets stuck in between packets and I can't send anything. Also I find it crashes with errors when you close the program while it is waiting for data to read and stuff.
I would love for it to be OOP (object oriented programming). Meaning making a object that is based off of TObject and has an event of OnPacket or something that is called when it gets a full packets with all the data and stuff and passes the data along to the event.
OnPacket(PacketID, Length, data)
Anyway, here is some source I got so far that I want to scratch and use some asycronious method... I'd really not like to have to deal with threads is if I don't have to.
while BNET.Connected do
PacketLength := (PacketLength SHL 8) + AByte;
on E: Exception do
Case StartPacket of
Case PacketID of
SID_CLANINVITE : OutPutBox.Lines.Add(' SID_CLANINVITE');
SID_CLANMOTD : OutPutBox.Lines.Add(' SID_CLANMOTD');
If Terminated then BNET.Disconnect;
PS - I'd love to be able to give more than 500 points for this too, but it won't let me. :)