sendMessage method
Send a message over this socket
This wraps the native srt_sendmsg2 function and allows sending
messages with control information (TTL, in-order delivery, etc.)
in message mode rather than stream mode.
text is the message data to send
ttl is the time-to-live in milliseconds (default -1 for infinite)
inOrder specifies whether the message must arrive in order (default false)
Returns the number of bytes actually sent.
Throws SrtException if sending fails
Implementation
int sendMessage(
String text, {
MessageControl control = const MessageControl(),
}) {
_checkNotClosed();
final payload = Uint8List.fromList(text.codeUnits);
// Create and initialize message control structure
final buffer = calloc<ffi.Char>(payload.length);
final mctrl = control.toNative();
try {
// Initialize message control
Srt.bindings.srt_msgctrl_init(mctrl);
// Copy payload to native buffer
for (int i = 0; i < payload.length; i++) {
buffer[i] = payload[i];
}
final bytesSent = Srt.bindings.srt_sendmsg2(
_socketHandle,
buffer,
payload.length,
mctrl,
);
checkSrtResult(bytesSent, operation: "send a menssage, no bytes sended");
return bytesSent;
} finally {
calloc.free(mctrl);
calloc.free(buffer);
}
}