R
R
Riot_riot2021-09-23 13:33:11
Node.js
Riot_riot, 2021-09-23 13:33:11

Error connecting to websocket (socket.io), how to connect?

Hello, I wrote a small service on a node using sockets, when I wrote for the test I used postman and everything works fine, 614c5705bf29b134228536.png
But when I started connecting from in the browser, I started getting an error

websocket.js:89 WebSocket connection to 'wss://myurl.com:3000/socket.io/?EIO=4&transport=websocket&sid=KnZ01Z8nT9vnHCpyAANf' failed:

no error details.
I tried all combinations of connection parameters that I found, in the spirit of:
{
      secure: true,
      rejectUnauthorized: false
 }

 {
      secure: true,
      transports: ['websocket'],
      withCredentials: true,
      rejectUnauthorized: false
 }

but it did not help.

The server with sockets is on a different domain, but I registered the corses,
require('socket.io')(server, {
            cors: {
                origin: '*',
                methods: ["GET", "POST"]
            }


Plus, I added a log to the connection event,
io.sockets
            .on('connection', (socket) => {
                try {
                    console.log('connection');

and when I try to connect from postman - everything is in order, I see it, but the browser does not call anything.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question