Inband Message Format
Inband message passing is enabled through the sock.inbandcommands property.
Each inband message has to start with a special escape character whose ASCII code is specified by the sock.escchar property. The next character after the escape character can have any ASCII code except for the code of the escape character itself.
Following that is the body of the inband message. The last character in the message is a so-called end character, specified by the sock.endchar property. It signals the end of the inband message and return to the "regular" data.
There are no specific limitations on how long the inband message can be. The length is only limited by how much space you allocate for the CMD and RPL buffers that store incoming and outgoing inband messages.
And what if the data stream itself contains a character(s) with the ASCII code of the escape character you have set? Wouldn't this confuse the socket into thinking that this is the beginning of inband command? To avoid this situation, the data character with the code of the escape character is transmitted as two identical characters with the same ASCII code.
Example: Suppose you have the following setup:
Now, you have the following data stream coming into the socket:
The socket will interpret this stream as including one inband command ("$#inband command%"), while the regular data ("ABCDEFG$123") would be placed into the RX buffer of the socket. The first "$" character is interpreted as the beginning of the inband message, because this character is followed by some other character ("#"). The second occurrence of the "$" character is interpreted as data, since this character is followed by another "$" character. The resulting data stream contains only a single "$" character — the socket takes care of removing the second one automatically.
When sending data from the TX buffer, the socket also automatically doubles all data characters with the ASCII code of the escape character. So, if you want to send this string: "Outbound$!" what will actually be sent is:
Inband messages are not our invention. Many programs treat the character with code 255 as an escape character.