I have a MQTT client in an internal network and an MQTT server somewhere in Cloud. How can I connect to MQTT Server without opening port in the Client network?
You don't need to open any ports to connect to an external broker on a normal NAT'd internal network (e.g. a normal domestic ADSL setup.).
As long as your network allows all outbound connections (and related replies) then it should all just work.
This is because all MQTT connections are initiated by the client and are then persistent until the client closes the connection. Messages for subscriptions just flow back down this existing connection.
If you need to explicitly allow outbound ports then the default port is 1883.
If you are on a more locked down network, e.g. a corporate network that requires you to use a proxy to reach the outside world then you have 2 choices.
- You need an OSI layer 5 proxy e.g. socks
- If you only have access to a HTTP proxy then you have to hope that your external broker and client supports MQTT over Websockets.