sendMessage method
Send a message to this peer
Implementation
@override
void sendMessage(List<int> message) {
// Check if peer is closed
if (_closed) {
throw ShspNetworkException(
'Cannot send message: peer is closed',
address: remotePeer.address.address,
port: remotePeer.port,
);
}
// Validate message is not empty
if (message.isEmpty) {
throw ShspValidationException(
'Message cannot be empty',
field: 'message',
value: message,
);
}
// Validate message size (UDP has a maximum packet size)
if (message.length > maxMessageSize) {
throw ShspValidationException(
'Message size ${message.length} exceeds maximum $maxMessageSize bytes',
field: 'message.length',
value: message.length,
);
}
// Note: sendTo is synchronous in Dart (UDP is non-blocking)
int bytes = socket.sendTo(message, remotePeer);
if (bytes == 0) {
throw ShspNetworkException(
'Failed to send message - socket buffer may be full',
address: remotePeer.address.address,
port: remotePeer.port,
);
}
}