TCP/IP Message Format

From QB64 Wiki

Jump to: navigation, search
About QB64 TCP/IP Formatted Messages
  • PRINT #... and INPUT #... send/receive data across a TCP/IP connection using formatted messages (as opposed to GET #... and PUT #... which stream raw data). Formatted messages contain the message data and a header automatically added by QB64 specifying other information about the message. The header format is unique to QB64. Knowledge of the specific header format is generally unnecessary for QB64 programmers but documented here for reference purposes. The message header format is compact and can be extended (if necessary) in the future.


QB64 TCP/IP Formatted Message Format

Structure:

[1 byte: description flags]
[0-4 bytes: length of data]
[? bytes: data]


Details:

[1 byte: description flags]
  • Bits 0-2 hold a value from 0 to 7 indicating how the length of the message's data can be obtained as follows:
0 means... the data is 0 bytes in length & [length of data] is not used
1 means... the data is 1 bytes in length & [length of data] is not used
2 means... the data is 2 bytes in length & [length of data] is not used
3 means... the data is 3 bytes in length & [length of data] is not used
4 means... the data is 4 bytes in length & [length of data] is not used
5 means... [length of data] is 1 unsigned byte holding the length of the data
6 means... [length of data] is 2 unsigned bytes holding the length of the data
7 means... [length of data] is 4 unsigned bytes holding the length of the data
  • Bit 7 (the top bit) is set to indicate that the message is incomplete and requires the next/following message to be appended to this message. In this way a long message may be deliberately sent as smaller messages and reassembled. In the following example a$ and b$ are combined into a single message/string by use of a semi-colon.
PRINT #connect_handle, a$;
PRINT #connect_handle, b$
  • Bits 3-6 must be set to 0


[0-4 bytes: length of data]
  • Depending on the value of bits 0-2 in [description flags] 'length of data' may or may not be used. If it is used its value indicates how many bytes of data are in the following message content. The size of 'length of data' may be 0, 1, 2 or 4 bytes.


[? bytes: data]

  • The raw data (content) of the message.


  • The PRINT # formatted header sent can be read by INPUT # and will return EOF(connect_handle) = 0 when the transfer is completed. EOF will return -1 while it is not completed. This formatting is not used normally, so both users must use QB64!



See also:

INPUT (TCP/IP statement), PRINT (TCP/IP statement)

_OPENCLIENT, _OPENHOST, INPUT #, PRINT #


Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Personal tools