send method
Send a message through the transport
Implementation
@override
void send(dynamic message) {
if (_isClosed) {
_logger.debug('Attempted to send message on closed transport');
return;
}
try {
final jsonMessage = jsonEncode(message);
_logger.debug('Encoding message: $message');
_logger.debug('Encoded JSON: $jsonMessage');
// Check if stdout is available and not bound
try {
_stdoutSink.writeln(jsonMessage);
_logger.debug('Sent message: $jsonMessage');
} catch (e) {
// If there's a StreamSink binding issue, handle gracefully
if (e.toString().contains('StreamSink is bound')) {
_logger.debug('StreamSink binding issue detected: $e');
_handleTransportError('StreamSink binding conflict');
} else {
rethrow;
}
}
} catch (e) {
_logger.debug('Error encoding or sending message: $e');
_logger.debug('Original message: $message');
// Don't rethrow to prevent process crash
}
}