diff --git a/lib/src/connectionhandling/server/mqtt_client_mqtt_server_ws2_connection.dart b/lib/src/connectionhandling/server/mqtt_client_mqtt_server_ws2_connection.dart index 40c5d43..82077de 100644 --- a/lib/src/connectionhandling/server/mqtt_client_mqtt_server_ws2_connection.dart +++ b/lib/src/connectionhandling/server/mqtt_client_mqtt_server_ws2_connection.dart @@ -278,7 +278,9 @@ class MqttServerWs2Connection extends MqttServerWsConnection { final c = Completer(); const endL = '\r\n'; final path = '${uri.path}?${uri.query}'; - final host = '${uri.host}:${uri.port.toString()}'; + final isDefaultPort = (uri.scheme == 'wss' && uri.port == 443) || + (uri.scheme == 'ws' && uri.port == 80); + final host = isDefaultPort ? uri.host : '${uri.host}:${uri.port}'; final now = DateTime.now().millisecondsSinceEpoch; final key = 'mqtt-$now'; final key64 = base64.encode(utf8.encode(key));