I am using mqtt_client: ^9.6.8 in my flutter project.
I want to subscribe to Korean topics, like topic: "test/안녕"
I want to get messages in Korean, like message: "안녕하세요"
currently if I try to subscribe to a korean topic, the client disconnects and the process just kills itself.
The log was a little bit different before, but this is the current log after I subscribe to a korean topic.
I/flutter (18972): 1-2022-08-09 15:38:40.135206 -- MqttConnectionBase::_onDone - calling disconnected callback
I/flutter (18972): 1-2022-08-09 15:38:40.135985 -- MqttConnectionKeepAlive::stop - stopping keep alive
I/flutter (18972): EXAMPLE::OnDisconnected client callback - Client disconnection
I/flutter (18972): EXAMPLE::OnDisconnected callback is unsolicited or none, this is incorrect - exiting
D/HostConnection(18972): createUnique: call
F/libc (18972): FORTIFY: pthread_mutex_lock called on a destroyed mutex (0xb400006dd36425a0)
D/HostConnection(18972): HostConnection::get() New Host Connection established 0xb400006de3607310, tid 19012
F/libc (18972): Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 19013 (1.raster), pid 18972
if I send a korean message, then it comes like HÅU± which is not what I want.
I tried to decode with utf8 but I can't seem to do it correctly.
Any helps on this? thanks for every suggestion!!
--edit--
this is the part where I print the received mqtt message
client.updates!.listen((List<MqttReceivedMessage<MqttMessage?>>? c) {
final recMess = c![0].payload as MqttPublishMessage;
final pt =
MqttPublishPayload.bytesToStringAsString(recMess.payload.message);
context.read<SubTopic>().newTopic(c[0].topic);
context.read<SubMessage>().newMessage(pt);
print('Notification: topic is <${c[0].topic}>, payload is <$pt>');
});
this is where I subscribe to the topic
try {
await client.connect();
} on NoConnectionException catch (e) {
print('EXAMPLE::client exception - $e');
client.disconnect();
} on SocketException catch (e) {
print('EXAMPLE::socket exception - $e');
client.disconnect();
}
if (client.connectionStatus!.state == MqttConnectionState.connected) {
print('EXAMPLE::Mosquitto client connected');
for (String topic in _subTopicList) {
print(topic);
client.subscribe(topic, MqttQos.exactlyOnce);
}
} else {
print(
'EXAMPLE::ERROR Mosquitto client connection failed - disconnecting, status is ${client.connectionStatus}');
client.disconnect();
// exit(-1);
}
below if client code config
KubernetesConnectionConfiguration kcfg = new KubernetesConnectionConfiguration();
kcfg.setNamespace(igniteK8sNameSpace);
kcfg.setServiceName(igniteK8sServiceName);
cfg.setAddressesFinder(new ThinClientKubernetesAddressFinder(kcfg));
cfg.setRetryPolicy(new ClientRetryAllPolicy());
after ignite pod restart
client throw Exception
org.apache.ignite.client.ClientConnectionException: Connection timed out
at org.apache.ignite.internal.client.thin.io.gridnioserver.GridNioClientConnectionMultiplexer.open(GridNioClientConnectionMultiplexer.java:144)
at org.apache.ignite.internal.client.thin.TcpClientChannel.<init>(TcpClientChannel.java:178)
at org.apache.ignite.internal.client.thin.ReliableChannel$ClientChannelHolder.getOrCreateChannel(ReliableChannel.java:917)
at org.apache.ignite.internal.client.thin.ReliableChannel$ClientChannelHolder.getOrCreateChannel(ReliableChannel.java:898)
at org.apache.ignite.internal.client.thin.ReliableChannel$ClientChannelHolder.access$200(ReliableChannel.java:847)
at org.apache.ignite.internal.client.thin.ReliableChannel.applyOnDefaultChannel(ReliableChannel.java:759)
at org.apache.ignite.internal.client.thin.ReliableChannel.applyOnDefaultChannel(ReliableChannel.java:731)
at org.apache.ignite.internal.client.thin.ReliableChannel.service(ReliableChannel.java:167)
at org.apache.ignite.internal.client.thin.ReliableChannel.request(ReliableChannel.java:288)
at org.apache.ignite.internal.client.thin.TcpIgniteClient.getOrCreateCache(TcpIgniteClient.java:185)
and i use retry to reconnect and print clientConfiguration.getAddressesFinder().getAddresses() and it address is pod address,but client not reconnect
while (retryTimeTmp < retryTimes) {
try {
return igniteClient.getOrCreateCache(new ClientCacheConfiguration()
.setName(cacheName)
.setAtomicityMode(TRANSACTIONAL)
.setCacheMode(PARTITIONED)
.setBackups(2)
.setWriteSynchronizationMode(PRIMARY_SYNC));
}catch (Exception e) {
LOGGER.error("get cache [{}] not success", cacheName, e);
LOGGER.error("get address info [{}], ipfinder [{}]", clientConfiguration.getAddresses(), clientConfiguration.getAddressesFinder().getAddresses());
retrySleep();
} finally {
retryTimeTmp++;
}
https://github.com/apache/ignite/pull/10110.
I pull request and fix this issue
I have this pattern:
channel ESANTE_MPI_CREATE_PATIENT_LISTENER (with a MLLP listener) calls channel ESANTE_MPI_CREATE_PATIENT that calls a TCP destination.
If connection cannot be done in the TCP destination inside ESANTE_MPI_CREATE_PATIENT then this channel reports an error for this destination:(ERROR: ConnectException: Connection refused (Connection refused))
The response transformer does not seem to be called (which is normal as there is no response).
I wonder how I can report the error back to the calling channel ESANTE_MPI_CREATE_PATIENT_LISTENER ?
PS: When tcp destination responds, then I use the response transformer to parse the received frame and create a response message (json error/ok) for the calling channel. Everything works fine here.
My question ends up with: How to trap a Connection refused in a TCP destination to create a response message.
I finally managed this by using the postprocessor script in ESANTE_MPI_CREATE_PATIENT to get the response of the connector and then force a message.
// fake error message prepared for connection refused.
// we put this as the response of the channel destination in order to force a understandable error message.
const sErrorMsg = {
status: "error",
error: "connection refused to eSanté MPI"
};
const TCP_CONNECTOR_ESANTE_MPI_RANK = 2; // WARNING: be sure to take the correct connector ID as displayed into destination.
const TCP_CONNECTOR_ESANTE_MPI_DNAME = 'd' + TCP_CONNECTOR_ESANTE_MPI_RANK; // WARNING: be sure to take the correct connector ID as displayed into destination.
/*
var cms = message.getConnectorMessages(); // returns message but as Immutable
responses. not what we want: we use responseMap instead.
var key = TCP_CONNECTOR_ESANTE_MPI_RANK;
logger.debug(" Response Data=" + cms.get(key).getResponseData());
logger.debug(" Response Data0=" + cms.get(key).getResponseError());
logger.debug(" Response Data1=" + cms.get(key).getResponseData().getError());
logger.debug(" Response Data2=" + cms.get(key).getResponseData().getMessage());
logger.debug(" Response Data3=" + cms.get(key).getResponseData().getStatusMessage());
logger.debug(" Response Data4=" + cms.get(key).getResponseData().getStatus());
*/
var responseMPI = responseMap.get(TCP_CONNECTOR_ESANTE_MPI_DNAME); // return a mutable reponse :-)
if (responseMPI.getStatus()=='ERROR' &&
responseMPI.getStatusMessage().startsWith('ConnectException: Connection refused')) {
// build a error message for this dedicated case
logger.error("connection refused detected");
responseMPI.setMessage(JSON.stringify(sErrorMsg)); // force the message to be responsed.
}
return;
I'm having an issue where if an audience member that has been promoted to Cohost exits the active livestream, the stream is ended for everyone. I only want the host that started the livestream to be able to end it, not a cohost.
I have the following code for changing the role from audience to Cohost:
The host sends a message to the audience member they want to promote to cohost --
widget.client.sendMessageToPeer(groups['id'].toString(), AgoraRtmMessage('Hey $username would you like to join this live?', 1, false)).onError((error, stackTrace) => print("Error: $error")) ;
The audience member receives the message and hits enter to accept the promotion to cohost. With the following config:
await _engine.setClientRole(ClientRole.Broadcaster);
await _engine.enableVideo();
client.addOrUpdateChannelAttributes(widget.channelName, [], true).onError((error, stackTrace) => print("Error: $error \n Stacktrace:$stackTrace"));
setState(() {
coHost = true;
});
Navigator.of(context).pop();
That works properly for changing the role of audience member to broadcaster(cohost).
However, when the cohost exits the active livestream it's terminated for everyone. I have the following code that's executed when the cohost exits the active stream:
print("Owner ID IS : $ownerId");
await client.sendMessageToPeer(ownerId, AgoraRtmMessage('I am leaving', 2, false)).whenComplete(() async{
print("Done");
await _engine.setClientRole(ClientRole.Audience);
client.addOrUpdateChannelAttributes(widget.channelName, [AgoraRtmChannelAttribute("TEST", "1")], true);
print("CHANNEL NAME IS :${widget.channelName}.");
I also get the following log output when the Cohost exits the live:
I/flutter ( 2510): Remote Video State is: VideoRemoteState.Stopped
I/flutter ( 2510): Remote Video Reason: VideoRemoteStateReason.RemoteMuted
I/flutter ( 2510): Remote Video State is: VideoRemoteState.Decoding
I/flutter ( 2510): Remote Video Reason: VideoRemoteStateReason.RemoteUnmuted
D/*WEBRTCN*( 2510): VideoRenderAndroid dtor
I/flutter ( 2510): userOffline: 1854772710
I/flutter ( 2510): Remote Video State is: VideoRemoteState.Stopped
I/flutter ( 2510): Remote Video Reason: VideoRemoteStateReason.RemoteOffline
I don't understand what's missing as I believe I'm following the reference docs correctly.
I am using the following for reference : https://docs.agora.io/en/Interactive%20Broadcast/faq/host_set_role
I'm receiving an error when connecting to my Mosquitto server in my flutter web project. I'm using the import for mqtt_browser_client.dart and the package mqtt_client.
My code follows the example, and I've checked, I am able to connect to my server from the same PC in MQTT Explorer. (becartpi:8080).
final client = MqttBrowserClient('ws://becArtPi', 'flutter');
void onPRessMQTTTest() async {
client.onDisconnected = onDisconnected;
client.onConnected = onConnected;
client.onSubscribed = onSubscribed;
client.logging(on: true);
client.port = 8080;
client.keepAlivePeriod = 20;
final connMess = MqttConnectMessage()
.withClientIdentifier('flutter')
.startClean() // Non persistent session for testing
.withWillQos(MqttQos.atLeastOnce);
print('EXAMPLE::Mosquitto client connecting....');
client.connectionMessage = connMess;
try {
await client.connect();
} on NoConnectionException catch (e) {
// Raised by the client when connection fails.
print('EXAMPLE::client exception - $e');
client.disconnect();
} on SocketException catch (e) {
// Raised by the socket layer
print('EXAMPLE::socket exception - $e');
client.disconnect();
} catch (e) {
print('MQTT Connection Error: $e');
}
client.updates!.listen((List<MqttReceivedMessage<MqttMessage?>>? c) {
final recMess = c![0].payload as MqttPublishMessage;
final pt =
MqttPublishPayload.bytesToStringAsString(recMess.payload.message);
print(
'EXAMPLE::Change notification:: topic is <${c[0].topic}>, payload is <-- $pt -->');
print('');
});
/// Check we are connected
if (client.connectionStatus!.state == MqttConnectionState.connected) {
print('EXAMPLE::Mosquitto client connected');
} else {
/// Use status here rather than state if you also want the broker return code.
print(
'EXAMPLE::ERROR Mosquitto client connection failed - disconnecting, status is ${client.connectionStatus}');
client.disconnect();
exit(-1);
}
const pubTopic = 'Dart/Mqtt_client/testtopic';
final builder = MqttClientPayloadBuilder();
client.publishMessage(pubTopic, MqttQos.exactlyOnce, builder.payload!);
}
void onDisconnected() {}
void onConnected() {
print(
'EXAMPLE::OnConnected client callback - Client connection was sucessful');
}
void onSubscribed(String topic) {}
EXAMPLE::Mosquitto client connecting....
1-2021-08-18 15:23:35.899 -- MqttClient::connect - keep alive is enabled with a value of 20 seconds
1-2021-08-18 15:23:35.900 -- MqttConnectionKeepAlive:: Initialised with a keep alive value of 20 seconds
1-2021-08-18 15:23:35.900 -- MqttConnectionKeepAlive:: Disconnect on no ping response is disabled
1-2021-08-18 15:23:35.901 -- MqttConnectionHandlerBase::connect - server ws://becArtPi/ws, port 8080
1-2021-08-18 15:23:35.901 -- SynchronousMqttBrowserConnectionHandler::internalConnect entered
1-2021-08-18 15:23:35.901 -- SynchronousMqttBrowserConnectionHandler::internalConnect - initiating connection try 0, auto reconnect in progress false
1-2021-08-18 15:23:35.902 -- SynchronousMqttBrowserConnectionHandler::internalConnect - calling connect
1-2021-08-18 15:23:35.902 -- MqttBrowserWsConnection::connect - entered
1-2021-08-18 15:23:35.903 -- MqttBrowserWsConnection::connect - WS URL is ws://becartpi:8080/ws
1-2021-08-18 15:23:35.906 -- MqttBrowserWsConnection::connect - connection is waiting
1-2021-08-18 15:23:36.068 -- MqttBrowserWsConnection::connect - websocket has erred
1-2021-08-18 15:23:36.069 -- SynchronousMqttBrowserConnectionHandler::internalConnect - connection complete
1-2021-08-18 15:23:36.069 -- SynchronousMqttBrowserConnectionHandler::internalConnect sending connect message
1-2021-08-18 15:23:36.069 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.connect
Header: MessageType = MqttMessageType.connect, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
Connect Variable Header: ProtocolName=MQIsdp, ProtocolVersion=3, ConnectFlags=Connect Flags: Reserved1=false, CleanStart=true, WillFlag=false, WillQos=MqttQos.atLeastOnce, WillRetain=false, PasswordFlag=false, UserNameFlag=false, KeepAlive=20
MqttConnectPayload - client identifier is : flutter
1-2021-08-18 15:23:36.072 -- SynchronousMqttBrowserConnectionHandler::internalConnect - pre sleep, state = Connection status is connecting with return code of noneSpecified and a disconnection origin of none
1-2021-08-18 15:23:41.098 -- SynchronousMqttBrowserConnectionHandler::internalConnect - post sleep, state = Connection status is connecting with return code of noneSpecified and a disconnection origin of none
1-2021-08-18 15:23:41.099 -- SynchronousMqttBrowserConnectionHandler::internalConnect - initiating connection try 1, auto reconnect in progress false
1-2021-08-18 15:23:41.099 -- SynchronousMqttBrowserConnectionHandler::internalConnect - calling connect
1-2021-08-18 15:23:41.099 -- MqttBrowserWsConnection::connect - entered
1-2021-08-18 15:23:41.100 -- MqttBrowserWsConnection::connect - WS URL is ws://becartpi:8080/ws
1-2021-08-18 15:23:41.100 -- MqttBrowserWsConnection::connect - connection is waiting
1-2021-08-18 15:23:41.276 -- MqttBrowserWsConnection::connect - websocket has erred
1-2021-08-18 15:23:41.276 -- SynchronousMqttBrowserConnectionHandler::internalConnect - connection complete
1-2021-08-18 15:23:41.276 -- SynchronousMqttBrowserConnectionHandler::internalConnect sending connect message
1-2021-08-18 15:23:41.277 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.connect
Header: MessageType = MqttMessageType.connect, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 21
Connect Variable Header: ProtocolName=MQIsdp, ProtocolVersion=3, ConnectFlags=Connect Flags: Reserved1=false, CleanStart=true, WillFlag=false, WillQos=MqttQos.atLeastOnce, WillRetain=false, PasswordFlag=false, UserNameFlag=false, KeepAlive=20
MqttConnectPayload - client identifier is : flutter
1-2021-08-18 15:23:41.277 -- SynchronousMqttBrowserConnectionHandler::internalConnect - pre sleep, state = Connection status is connecting with return code of noneSpecified and a disconnection origin of none
1-2021-08-18 15:23:46.318 -- SynchronousMqttBrowserConnectionHandler::internalConnect - post sleep, state = Connection status is connecting with return code of noneSpecified and a disconnection origin of none
1-2021-08-18 15:23:46.318 -- SynchronousMqttBrowserConnectionHandler::internalConnect - initiating connection try 2, auto reconnect in progress false
1-2021-08-18 15:23:46.319 -- SynchronousMqttBrowserConnectionHandler::internalConnect - calling connect
1-2021-08-18 15:23:46.319 -- MqttBrowserWsConnection::connect - entered
1-2021-08-18 15:23:46.319 -- MqttBrowserWsConnection::connect - WS URL is ws://becartpi:8080/ws
1-2021-08-18 15:23:46.320 -- MqttBrowserWsConnection::connect - connection is waiting
1-2021-08-18 15:23:46.487 -- MqttBrowserWsConnection::connect - websocket has erred
1-2021-08-18 15:23:46.487 -- SynchronousMqttBrowserConnectionHandler::internalConnect - connection complete
1-2021-08-18 15:23:46.487 -- SynchronousMqttBrowserConnectionHandler::internalConnect sending connect message
1-2021-08-18 15:23:46.488 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.connect
Header: MessageType = MqttMessageType.connect, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 21
Connect Variable Header: ProtocolName=MQIsdp, ProtocolVersion=3, ConnectFlags=Connect Flags: Reserved1=false, CleanStart=true, WillFlag=false, WillQos=MqttQos.atLeastOnce, WillRetain=false, PasswordFlag=false, UserNameFlag=false, KeepAlive=20
MqttConnectPayload - client identifier is : flutter
1-2021-08-18 15:23:46.488 -- SynchronousMqttBrowserConnectionHandler::internalConnect - pre sleep, state = Connection status is connecting with return code of noneSpecified and a disconnection origin of none
1-2021-08-18 15:23:51.521 -- SynchronousMqttBrowserConnectionHandler::internalConnect - post sleep, state = Connection status is connecting with return code of noneSpecified and a disconnection origin of none
1-2021-08-18 15:23:51.522 -- SynchronousMqttBrowserConnectionHandler::internalConnect failed
EXAMPLE::client exception - mqtt-client::NoConnectionException: The maximum allowed connection attempts ({3}) were exceeded. The broker is not responding to the connection request message (Missing Connection Acknowledgement?
1-2021-08-18 15:23:51.523 -- MqttConnectionHandlerBase::disconnect - entered
1-2021-08-18 15:23:51.523 -- MqttConnectionHandlerBase::_performConnectionDisconnect entered
Connection in MQTT Explorer which is connecting and receiving messages correctly.
mosquitto.log
1629283989: Socket error on client 8caab5860e74, disconnecting.
1629284712: Socket error on client <unknown>, disconnecting.
1629284717: Socket error on client <unknown>, disconnecting.
1629284722: Socket error on client <unknown>, disconnecting.
Check the websocket headers API setting you may be sending the wrong headers for your broker.
Have a look at the mqtt_server_client_websocket.dart file in the examples directory, the setting you want is client.websocketProtocols, look at the API for this.