Is it possible to configure the Aedes broker to allow client connections over both TCP and WS? #938
-
I am looking to configure my Aedes broker to achieve the scenario in the title. I am currently in a scenario where I have a client that can only connect to the broker over websockets and another client that connects over HTTP. It might be possible for me to configure the second client to connect over websockets but I would like to explore what I mentioned above before proceeding to configure the client to connect over HTTP. I am currently able to achieve the intended behavior I want but on two different ports i.e, the server is listening for HTTP connections on port 1883 and for websocket connections on port 8888. I have attached the current implementation below: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I usually bind the ws/wss to the express server and then create a separete broker connection for plain tcp/tls. This is how I bind the ws server: import { createWebSocketStream, Server as WsServer } from 'ws'
const wsServer = new WsServer({ server: // your http server })
wsServer.on('error', err => {
console.error(err, 'WebSocket error')
})
wsServer.on('connection', (conn, req) => {
const stream = createWebSocketStream(conn)
stream._socket = conn._socket
broker.handle(stream, req)
}) |
Beta Was this translation helpful? Give feedback.
Websockets can only be enabled on http servers not tcp streams so you cannot for use the server you create to listen to 1883 to also accept websocket at least for what I know