Closed andrys2007 closed 4 months ago
Are you getting any errors? I've just tested it and the example in https://github.com/websockets/ws/blob/5e42cfdc5fa114659908eaad4d9ead7d5051d740/examples/ssl.js works fine.
Hello. No, there are no errors. It just doesn't connect. It doesn't respond in any way. At the same time, if I run the WS code, it works fine, but the problem is specifically with WSS. Could the issue be with the certificates? I'm connecting from this client: https://test2.e-task.kz/ (test).
look WS server and clinet :
const WebSocket = require('ws');
const wsServer = new WebSocket.Server({ port: 3300 });
wsServer.on('connection', onConnect);
function onConnect(wsClient) {
console.log('New user');
wsClient.send('Hi');
wsClient.on('close', function() {
console.log('User disconnected');
});
wsClient.on('message', function(message) {
console.log(message);
try {
const jsonMessage = JSON.parse(message);
switch (jsonMessage.action) {
case 'ECHO':
wsClient.send(jsonMessage.data);
break;
case 'PING':
setTimeout(function() {
wsClient.send('PONG');
}, 2000);
break;
default:
console.log('bad command');
break;
}
} catch (error) {
console.log('error', error);
}
});
}
console.log('server start. Port: 3300 ');
Test clinet ws: http://test.lorcenter.kz/
This code works.
Could the issue be with the certificates?
Yes. The certificate in the example is self signed. It looks like Chrome does not give you details but if you open the console in Safari and write this code
new WebSocket('wss://192.168.1.188:3300')
you get something like this
WebSocket connection to 'wss://192.168.1.188:3300/' failed: The certificate for this server is invalid. You might be connecting to a server that is pretending to be “192.168.1.188” which could put your confidential information at risk.
This is not a ws issue.
I checked in Firefox, Chrome, and Opera.
I've made new certificates, but it still doesn't help. How else can we test it?
For example, maybe we can first test HTTPS to see if it works and then test WSS
I've made new certificates, but it still doesn't help. How else can we test it?
The certificate must be signed by a trusted CA.
For example, maybe we can first test HTTPS to see if it works and then test WSS.
Yes, you can use OpenSSL. For example:
openssl s_client -connect websocket-echo.com:443
How can I make a proper certificate? After all, it shouldn't be tied to a specific domain
It should. Certificates are for domains. For local testing you can use something like this https://github.com/FiloSottile/mkcert.
The thing is, the local one doesn't work either. Okay, I'll try to do it through a trusted organization now. I'll let you know about the results
I'm closing this as answered.
Now I'm starting to understand, and it turns out that the connection must be made on a host with a domain name. Moreover, they write that for WSS, you need to connect via the domain name, only through WSS://domainname.com. I wonder how this will look in the settings?
Is there an existing issue for this?
Description
Greetings, everyone. I downloaded this code. I wanted to check how WebSockets with SSL (WSS) work. I'm running the example ..\examples\ssl.js
In it, I explicitly specified the port: 3300
But for some reason, the example doesn't work. What could be the problem?
I tried another option:
Port 3300 is open for me, I'm checking the WS server on it, everything works fine.
ws version
wss
Node.js Version
v20.11.1
System
Window 10, window server 2019
Expected result
not
Actual result
not
Attachments
not