Reputation: 1
I'm completely lost at this point, so any insights would be most appreciated...
I'm maintaing code that creates a secure websocket using express. The original socket.io libraries were v1 which I've updated to v4 along with node 20.10 (from 14.7).
The problem is that I cannot get secure websocket connections to work -- the client simply comes back with connection failed. The client does successfully connect to the secure express server on port 443 to receive the websocket connection port info. A port tester confirms that the socket port 4321 is open. Connecting to the socket also fails using an online socket tester with the connection string: wss://{hostname}.com:4321/socket.io/?EIO=4&transport=websocket' Based on that, I have to believe my client code has nothing to do with the problem. But I can't think of what might be wrong with the server setup... Could it have to do with CORS somehow? Somehow related to it's being an Azure VM?
I'm hoping this is something obvious since it's a large code base. I can still run the old server, and secure connections still work using the same certificates. The new code tries to connect with EIO=4 when the old code connected with EIO=3.
This is what I think the relevant code might be:
node_modules: "socket.io": "^4.7.2", "socket.io-client": "^4.7.2",
Server:
import { Server, Socket } from 'socket.io';
...
io = new Server(createServer(SSL.Credentials, app));
io.listen(port); // port = 4321
Client:
import { io, Socket } from 'socket.io-client';
...
_socket = io(`wss://${hostname}:4321`,
{
transports: ['websocket'],
rejectUnauthorized: false
});
The runtime client error is:
websocket.js:43 WebSocket connection to 'wss://{hostname}.com:4321/socket.io/?EIO=4&transport=websocket' failed:
doOpen @ websocket.js:43
open @ transport.js:46
open @ socket.js:170
Socket @ socket.js:111
open @ manager.js:108
Manager @ manager.js:39
lookup @ index.js:29
init @ DocServer.ts:192
I tried making the connection use EIO=3 but couldn't figure out how to do that. I also tried reverting just the networking code, but wasn't successful due to other package upgrading issues.
Upvotes: 0
Views: 73
Reputation: 1
Okay, figured it out. The server code needs to be changed to listen to the httpsServer
, not the socket.io
server
const httpsServer = createServer(SSL.Credentials);
io = new Server(httpsServer, {})
httpsServer.listen(port); // port = 4321
Upvotes: 0