sendMessage method
Sends a message to the WebSocket server.
This method sends a text message to the server if the WebSocket connection is open. Prints an error message to the console if there is no active connection.
message: The message to be sent to the server.
Implementation
void sendMessage(String message) {
if (_socket != null) {
_socket!.add(message); // Send the message through the WebSocket.
debugPrint('Sent message: $message');
} else {
debugPrint('No connection to send message.');
}
}