# Websoket connection to wss://localhost:8883 failed trying to connect to HiveMQ Cloud

**URL:** <https://community.hivemq.com/t/websoket-connection-to-wss-localhost-8883-failed-trying-to-connect-to-hivemq-cloud/1800>\
**Category:** HiveMQ Client Library\
**Created:** [February 1, 2023, 3:03am UTC](https://community.hivemq.com/t/websoket-connection-to-wss-localhost-8883-failed-trying-to-connect-to-hivemq-cloud/1800 "2023-02-01T03:03:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![icode](https://avatars.discourse-cdn.com/v4/letter/i/f475e1/32.png) [@icode](https://community.hivemq.com/u/icode)\
**Post date:** [February 1, 2023, 3:03am UTC](https://community.hivemq.com/t/websoket-connection-to-wss-localhost-8883-failed-trying-to-connect-to-hivemq-cloud/1800/1 "2023-02-01T03:03:22Z")

</div>

hi, I’m using the HiveMQ ‘Getting started’ code example using MQTT.JS over a web browser (Chrome) in a React app and I get this error.

**WebSocket connection to ‘wss://localhost:8883/’ failed:**

I also get the error when I use port: 8884 and I even get it when I use protocol **WS**.

my code looks like this:

```auto

import React, { useEffect } from 'react'

import * as mqtt from 'mqtt'

const ReactComponent = ()=> {
    var options = {
		host: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.s1.eu.hivemq.cloud',
		port: 8883,
		protocol: 'mqtts',
		username: 'myname',
		password: 'mypassword'
	}

	useEffect(() => {
		let client = mqtt.connect(options)
		client.on('connect', function() {
			console.log('Connected')
			// Subscribe to a topic
			client.subscribe('testing', function(err) {
				if (!err) {
					// Publish a message to a topic
					client.publish('testing', 'Hello mqtt')
				}
			})
		})
	}, [])

```

Does anyone know what could be happening wrong?

---

<div class="post-metadata">

**Author:** ![Daria\_H](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@Daria\_H](https://community.hivemq.com/u/Daria_H)\
**Post date:** [February 1, 2023, 12:58pm UTC](https://community.hivemq.com/t/websoket-connection-to-wss-localhost-8883-failed-trying-to-connect-to-hivemq-cloud/1800/2 "2023-02-01T12:58:02Z")

</div>

Hi @icode ,

It is great that you are interested in MQTT and HiveMQ, welcome to our community!

WebSocket port is 8884.

I hope it helps.

Regards,  
Dasha from HiveMQ Team
