How to connect to WebSocket with wss://

Hi,

I am currently building an Flutter app and want to use WebSocket to subscribe the MQTT.

This code snippet is from Flutter documentation:

final channel = WebSocketChannel.connect(
  Uri.parse('wss://**echo.websocket.events**'),
);

I tried to replace echo.websocket.events with my Cluster URL, but it did not work.

How can I configure this?

Hi @sback2063 ,

You indicated you “tried to replace echo.websocket.events with my Cluster URL, but it did not work.”

Did you try to replace it with wss://clusterurl:8884 or wss://clusterurl:8884/mqtt?

Regards,
Dasha from HiveMQ team

Hi @Daria_H ,

Thank you for your response.

I tried wss://clusterurl:8884/mqtt, this worked. :slight_smile:

I have two additional questions:

  1. How can we connect and publish message from PHP without using pecl?
    My hosting does not allow me to use terminal command for security reason.
    It can use php and composer commands.

  2. What is the difference between using WebSocket (ws:) and without using WebSocket (wss:)?
    Which one is more secure?

Thanks,

Hi @sback2063 ,

  1. I cannot help with PHP, sorry.

  2. ws: stands for WebSocket and wss: for Secure WebSocket, the secure one is more secure :wink:

However HiveMQ Cloud supports only secure (SSL encrypted) connections. Port 8884 is for Secure WebSocket and port 8883 is for TCP (TLS).

I hope this helps,
Kind regards,
Dasha

Hi @Daria_H ,

Thanks! That helped me a lot! :slight_smile:

If third-party library uses tcp: to connect the broker, is it same like when I connect with wss:?
Example: tcp://clusterurl:8884/mqtt

Thanks,

Hi sback2063,

That would usually depend on what format a library is using, though I would guess one would use the typical wss:// and manage “tcp behind the scenes”.

Do you have an example library you are wanting to use? (The reference documentation hopefully gives examples of which format the strings should take)

Thanks,
Seth - HiveMQ Support