Skip to content

TCP Mode ​

Identified with the label

TCP
, the TCP mode of Layrz Protocol is designed for realtime implementations, where the latency is critical. This mode allows devices to communicate over a reliable connection, ensuring that packets are delivered in the order they were sent and without loss.

Features ​

  • Reliable Connection: TCP ensures that all packets are delivered without loss and in the correct order.
  • Real-time Communication: Ideal for applications where low latency is crucial, such as IoT devices that require immediate responses.
  • Stream-based: TCP allows for continuous data streams, making it suitable for applications that require ongoing communication.

Disadvantages ​

  • Data consumption: TCP can consume more resources compared to other modes, as it maintains a connection and ensures reliability.
  • Complexity: Implementing TCP can be more complex due to the need for connection management and error handling.

Communication Flow ​

Considerations ​

Sometimes, when the server is under load, you may receive two packets in a row, for that, you need to split the packets manually, we recommend using a RegExp to split the packets, like this:

dart
/* DART EXAMPLE */
String raw = utf8.decode(rawMessage);

final packets = raw.split(RegExp(r'(?=<(?:A\w{1})>)')).where((message) {
  return message.isNotEmpty;
}).map((message) {
  return message.trim();
}).toList();

// Input: <Ab>FED70CC14B43:ELA_PUCK_RHT;A4C138952028:GENERIC;A4C138755191:GENERIC;A4C138A6FD30:GENERIC;A4C1386C1B5E:GENERIC;05ED</Ab><Ao>1738687236;9068</Ao>
// Output: [<Ab>FED70CC14B43:ELA_PUCK_RHT;A4C138952028:GENERIC;A4C138755191:GENERIC;A4C138A6FD30:GENERIC;A4C1386C1B5E:GENERIC;05ED</Ab>, <Ao>1738687236;9068</Ao>]
python
""" PYTHON EXAMPLE """
raw_message: str = data.decode('utf-8').strip()
split_messages: list[str] = re.split(r'(?=<(?:A\w{1})>)', raw_message)
messages: list[str] = [msg.strip() for msg in split_messages if msg]

# Input: <Ab>FED70CC14B43:ELA_PUCK_RHT;A4C138952028:GENERIC;A4C138755191:GENERIC;A4C138A6FD30:GENERIC;A4C1386C1B5E:GENERIC;05ED</Ab><Ao>1738687236;9068</Ao>
# Output: ["<Ab>FED70CC14B43:ELA_PUCK_RHT;A4C138952028:GENERIC;A4C138755191:GENERIC;A4C138A6FD30:GENERIC;A4C1386C1B5E:GENERIC;05ED</Ab>", "<Ao>1738687236;9068</Ao>"]