diff --git a/ChangeLog.txt b/ChangeLog.txt
index 54874a5b..a3f9e35f 100644
--- a/ChangeLog.txt
+++ b/ChangeLog.txt
@@ -46,6 +46,7 @@ Client:
- Add --retained-only to mosquitto_sub to exit after receiving all retained
messages.
- Connections now default to using MQTT v3.1.1.
+- Default to using port 8883 when using TLS.
1.4.7 - 20151221
diff --git a/client/client_shared.c b/client/client_shared.c
index 486d4164..8fe0be36 100644
--- a/client/client_shared.c
+++ b/client/client_shared.c
@@ -37,7 +37,7 @@ static int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int
void init_config(struct mosq_config *cfg)
{
memset(cfg, 0, sizeof(*cfg));
- cfg->port = 1883;
+ cfg->port = -1;
cfg->max_inflight = 20;
cfg->keepalive = 60;
cfg->clean_session = true;
@@ -428,6 +428,7 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
if(!strncasecmp(url, "mqtt://", 7)) {
url += 7;
+ cfg->port = 1883;
} else if(!strncasecmp(url, "mqtts://", 8)) {
url += 8;
cfg->port = 8883;
@@ -831,15 +832,32 @@ int client_connect(struct mosquitto *mosq, struct mosq_config *cfg)
{
char err[1024];
int rc;
+ int port;
+
+#ifdef WITH_TLS
+ if(cfg->port < 0){
+ if(cfg->cafile || cfg->capath
+#ifdef WITH_TLS_PSK
+ || cfg->psk
+#endif
+ ){
+ port = 8883;
+ }else{
+ port = 1883;
+ }
+ }else{
+ port = cfg->port;
+ }
+#endif
#ifdef WITH_SRV
if(cfg->use_srv){
rc = mosquitto_connect_srv(mosq, cfg->host, cfg->keepalive, cfg->bind_address);
}else{
- rc = mosquitto_connect_bind(mosq, cfg->host, cfg->port, cfg->keepalive, cfg->bind_address);
+ rc = mosquitto_connect_bind(mosq, cfg->host, port, cfg->keepalive, cfg->bind_address);
}
#else
- rc = mosquitto_connect_bind(mosq, cfg->host, cfg->port, cfg->keepalive, cfg->bind_address);
+ rc = mosquitto_connect_bind(mosq, cfg->host, port, cfg->keepalive, cfg->bind_address);
#endif
if(rc>0){
if(!cfg->quiet){
diff --git a/man/mosquitto_pub.1.xml b/man/mosquitto_pub.1.xml
index 9b78fbf9..2fe2576e 100644
--- a/man/mosquitto_pub.1.xml
+++ b/man/mosquitto_pub.1.xml
@@ -238,9 +238,12 @@
- Specify specify user, password, hostname, port and topic at once as a URL.
- The URL must be in the form:
- mqtt(s)://[username[:password]@]host[:port]/topic
+ Specify specify user, password, hostname, port and
+ topic at once as a URL. The URL must be in the form:
+ mqtt(s)://[username[:password]@]host[:port]/topic
+ If the scheme is mqtt:// then the port defaults to
+ 1883. If the scheme is mqtts:// then the port defaults
+ to 8883.
@@ -268,7 +271,9 @@
- Connect to the port specified instead of the default 1883 for plain MQTT and 8883 for MQTT over TLS.
+ Connect to the port specified. If not given, the
+ default of 1883 for plain MQTT or 8883 for MQTT over
+ TLS will be used.
diff --git a/man/mosquitto_sub.1.xml b/man/mosquitto_sub.1.xml
index 616cfbde..d4d579f5 100644
--- a/man/mosquitto_sub.1.xml
+++ b/man/mosquitto_sub.1.xml
@@ -267,9 +267,12 @@
- Specify specify user, password, hostname, port and topic at once as a URL.
- The URL must be in the form:
- mqtt(s)://[username[:password]@]host[:port]/topic
+ Specify specify user, password, hostname, port and
+ topic at once as a URL. The URL must be in the form:
+ mqtt(s)://[username[:password]@]host[:port]/topic
+ If the scheme is mqtt:// then the port defaults to
+ 1883. If the scheme is mqtts:// then the port defaults
+ to 8883.
@@ -286,7 +289,9 @@
- Connect to the port specified instead of the default 1883 for plain MQTT and 8883 for MQTT over TLS.
+ Connect to the port specified. If not given, the
+ default of 1883 for plain MQTT or 8883 for MQTT over
+ TLS will be used.