# How we can connect MQTT via 443 port

**URL:** <https://community.hivemq.com/t/how-we-can-connect-mqtt-via-443-port/385>\
**Category:** HiveMQ Client Library\
**Created:** [November 26, 2020, 10:41am UTC](https://community.hivemq.com/t/how-we-can-connect-mqtt-via-443-port/385 "2020-11-26T10:41:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ranaaamer](https://avatars.discourse-cdn.com/v4/letter/r/3ec8ea/32.png) [@ranaaamer](https://community.hivemq.com/u/ranaaamer)\
**Post date:** [November 26, 2020, 10:41am UTC](https://community.hivemq.com/t/how-we-can-connect-mqtt-via-443-port/385/1 "2020-11-26T10:41:46Z")

</div>

I want to make a connection by using the 443 port. The reason is that I used SSL port 8883. But on some routes, this port blocked. So I want to use secure 443. Can you tell me the example, how I can connect?

---

<div class="post-metadata">

**Author:** ![seti](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.hivemq.com/seti/32/30_2.png) [@seti](https://community.hivemq.com/u/seti)\
**Post date:** [November 26, 2020, 10:55am UTC](https://community.hivemq.com/t/how-we-can-connect-mqtt-via-443-port/385/2 "2020-11-26T10:55:34Z")

</div>

Hi @ranaaamer and welcome to the forum 🙂

You can specify the port of the server in the client builder:

```
  Mqtt5AsyncClient client = MqttClient.builder()
    .useMqttVersion5()
    .serverHost("localhost")
    .serverPort(443); 
    .sslWithDefaultConfig()
    .buildAsync();

  client.connect();

```

Does this answer your question?

Best regards  
Till

---

<div class="post-metadata">

**Author:** ![ranaaamer](https://avatars.discourse-cdn.com/v4/letter/r/3ec8ea/32.png) [@ranaaamer](https://community.hivemq.com/u/ranaaamer)\
**Post date:** [November 26, 2020, 11:05am UTC](https://community.hivemq.com/t/how-we-can-connect-mqtt-via-443-port/385/3 "2020-11-26T11:05:11Z")

</div>

> [@seti](#):
>
> `Mqtt5AsyncClient`

Hi @seti thanks for your time. I tried but no luck, here is the code.

MqttClientSslConfig clientSslConfig = MqttClientSslConfig.builder().keyManagerFactory(SSLUtils.getKeyManagerFactoryWithPFX(\_context, “”)).trustManagerFactory(SSLUtils.getTrsutManagerFactorWithPFX(\_context)).protocols(Collections.singletonList(TlsVersion.TLS\_1\_2.javaName())).build();  
MqttClientTransportConfig mqttClientTransportConfig = MqttClientTransportConfig.builder().serverPort(443).serverHost(AppMode.appRunningMode.getSslUrl()).sslConfig(clientSslConfig).mqttConnectTimeout(5, TimeUnit.SECONDS).build();  
MqttClientAutoReconnect autoReconnect = MqttClientAutoReconnect.builder().initialDelay(3, TimeUnit.SECONDS).maxDelay(5, TimeUnit.SECONDS).build();  
mqttAndroidClient = Mqtt3Client.builder()  
.addConnectedListener(this)  
.automaticReconnect(autoReconnect)  
.addDisconnectedListener(this)  
.identifier(UUID.randomUUID().toString())  
.transportConfig(mqttClientTransportConfig) // 8883  
.buildAsync();  
mqttAndroidClient.connectWith().keepAlive(12).cleanSession(true).send();

Should I add https with serverhost.
