FLAP transport (version 1.0) |
|
|
FLAP is a low-level communications protocol that facilitates the development of
higher-level, datagram-oriented, communications layers. It is used on the TCP
connection between all clients and servers. Here is format of FLAP datagram:
|
2A |
|
byte |
|
FLAP id byte |
xx |
|
byte |
|
FLAP channel |
xx xx |
|
word |
|
FLAP datagram seq number |
xx xx |
|
word |
|
FLAP data size |
|
|
|
|
FLAP id byte is always 0x2A. It is frame-start sign.
The flap sequence numbers used for errors detection. So server can detect problem
when client set flap data size field = 10 and write 20 bytes 0x2A as data. The flap
sequence number origins are picked quite randomly. There is no connection between
the sequence number set from the server and the set from the client. Sequence numbers are
always incremented upward (towards 0x8000) for each command sent. If the sequence number
does reach 0x8000, it will wrap to 0x0000, for obvious reasons. If you start a new connection,
it is recommended that a new sequence number origin is picked for that connection, for purposes
of internal coherency. Sequence numbers are independent of channels: there's a single series
of sequence numbers per TCP connection (per socket).
Channels are the method used to multiplex separate paths of communication across the same
TCP socket. These are analogous to TCP/UDP port numbers. Five channels are currently used
by OSCAR:
- 0x01 - New Connection Negotiation
- 0x02 - SNAC data
- 0x03 - FLAP-level Error
- 0x04 - Close Connection Negotiation
- 0x05 - Keep alive
After a new connection (socket) is set up using channel 0x01, data should only be carried
on channel 0x02, until a low-level FLAP error occurs (channel 0x03) or there is planned
termination, which gets "negotiated" (on channel 0x04). Most live events processed during
the lifespan of the client are done over channel 0x02. SNACs are
never transmitted on any channel other than 0x02
The best way to read an incoming FLAP command is to first read only the starting 6 bytes
(the FLAP headers). From these 6bytes, you can determine how many more bytes you need to
read to complete the command, and how much memory you need to allocate to store it. Never
read more or less than the number of bytes specified in the FLAP headers, or your read will
result in a truncated or uninterpretable command. (If you read too much, you will probably
end up reading the start of the next command, which is bad. Lost data is unacceptable in
the AIM standard.)
Because every command must follow FLAP guidelines, I'd recommend using a low-level routine
to add the FLAP headers (normally, this will be the "flush transmit queue" routine, so that
addition of sequence numbers and the rest of the FLAP headers is done as close timewise as
possible to the command being put on the wire). This is the best way to prevent out-of-order
seqnums from getting used (which, as stated earlier, is quite fatal).
|
|
|
|
|