D
D
dfhkjhg2020-06-27 02:46:05
Node.js
dfhkjhg, 2020-06-27 02:46:05

Why does the socket return an error?

const WebSocket = require('ws')
const fetch = require('node-fetch')
const hooman = require('hooman')

const eventHandler = msg => {
    console.log(msg)
}

;(async () => {
    var response = await hooman("https://ws.site.org:2096/socket.io/?EIO=3&transport=polling&t="+ new Date().getTime(), {
        "headers": {
        "accept": "*/*",
        },
        "credentials": "include"
    });
    var data = await response.body
    var json = JSON.parse(data.match(/{.+}/)) тут хранится sid нужный для подключения
    console.log(json) 

    const ws = new WebSocket(`wss://ws.site.org:2096/socket.io/?EIO=3&transport=websocket&sid=${json.sid}`);

    ws.on('error', error => {
        console.error(error)
    })

    ws.addEventListener('message', eventHandler)
    
})()


Returns an error during connection

Error: Unexpected server response: 503
at ClientRequest. (C:\Users\ya\Desktop\auto\node_modules\ws\lib\websocket.js:580:7)

Maybe someone knows what could be the problem

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