Sending / Receiving Messages¶
The following guide is only for direct TCP connections, not for Websocket connections.
For Websocket you send/receive messages based on Websocket standards.
Sending¶
To send your proto message follow these steps:
- Change the proto message object to the bytes array (Protocol Buffer encoding) by using Google Protocol Buffer SDK for your programming language.
- Get the length of the byte array, change it to byte array, reverse it
- Send the reversed length + message byte array to the connection stream.
Receiving¶
To receive Proto messages you have to follow these steps:
- Receive the first four bytes, that's the message length, reverse the byte array, and change it to integer.
- Use the length and receive / read that amount of bytes from the stream.
- Now you have the full message bytes, use Google Protocol Buffer SDK for your programming language to deserialize the message to ProtoMessage.
- Use the ProtoMessage payloadType field to find the actual message type, then deserialize the payload with Google Protocol Buffer SDK to that message type.
Note
The system architecture is little-endian (that is, little end first), that's why we have to reverse the length byte array before sending.
Last update: February 6, 2023