Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between port and listener in MQTT

I have installed mosquitto client for MQTT on my local machine. I have below configuration:

listener 1883
protocol mqtt
listener 9001
protocol websockets

What is the difference between running client on mqtt and websockets. Also what is the difference if i change listener to port?

like image 381
Aquarius24 Avatar asked Dec 18 '22 13:12

Aquarius24


2 Answers

That means it will listen :1883 and expect MQTT packets and also listen :9001 and expect HTTP/Websocket protocol.

Wire protocol is the language programs speak. Sometimes appropriate talk is "Yo sup TJ", sometimes you should say "Good morning, mr. Marvel". Same thing in server communication. We're still inventing more languages.

  • MQTT http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html
  1. establish TCP connection
  2. now we're talking MQTT
  3. send MQTT packets as defined by standard (publish/sub/unsub) or disconnect
  • Websocket protocol, https://www.rfc-editor.org/rfc/rfc6455
  1. establish TCP connection
  2. send HTTP request with Upgrade: websocket header and other preparation
  3. except 101 Switching Protocols response
  4. now we're talking Websocket, either side can send messages as defined by standard

Port is a number in range 1 to 65535. IP address + port pair define an endpoint of communication. In some sense, port extends IP address space to specify to what program on the other computer you intend to send your data. For example, HTTP servers usually listen port 80.

To make life more interesting, sometimes you pick random port to listen because

  • community has not yet reached consensus which one is good for new application
  • your network administrator only allows certain ports
  • attempt to convince yourself that non-standard port adds security
  • well known port is already taken by another application
  • just feel like having fun confusing other people
like image 122
temoto Avatar answered Mar 31 '23 22:03

temoto


Mqtt client on websocket(Eclipse Paho javascript client) could be run from a web browser as in example(1). Normal mqtt clients runs on top of TCP and hence cannot be used directly from a web browser. Websockets run on top of HTTP and could be used directly from web browsers. If you are trying mosquitto broker, then it need to be compiled explicity with websocket support(2)

Ports vs Listeners, See mosquitto.conf file(3).

  • Port - used by default mosquitto broker listener.
  • Listener - By using this variable multiple times, mosquitto can listen on more than one port. Listeners also allow settings like max connections per listener, protocol etc.
like image 37
kiranpradeep Avatar answered Mar 31 '23 20:03

kiranpradeep