WebSocket what solution this errno: -4039

my js code:

const WebSocket = require('ws');
const ws = new WebSocket('wss://stream.binance.com:9443/ws');
const msg = {
  method: 'SUBSCRIBE',
  params: ['btcusdt@depth'],
  id: 1,
};

ws.onopen = () => {
  ws.send(JSON.stringify(msg));
};

ws.on('message', (data) => {
  console.log(data)
});

setTimeout(() => ws.close(), 40000)

and i got error:

at ClientRequest.emit (events.js:400:28)
    at TLSSocket.socketErrorListener (_http_client.js:475:9)
    at TLSSocket.emit (events.js:400:28)
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:82:21) {
  errno: -4039,
  code: 'ETIMEDOUT',
  syscall: 'connect',
  address: '128.121.243.228',
  port: 9443

if i change “wss://stream.binance.com:9443/ws” to “wss://testnet.binance.vision:9443/ws”
i can got response and data:

"{"result":null,"id":1}"

{"e":"depthUpdate","E":1636513787885,"s":"BTCUSDT","U":5215096,"u":5215105,"b":[["66538.08000000","0.00000000"],["66537.98000000","0.00000
000"],["66536.90000000","0.00751500"],["66536.89000000","0.00751500"]],"a":[["66536.91000000","0.00751500"],["66538.09000000","0.00000000"
],["66542.82000000","0.00000000"],["66543.57000000","0.00751400"],["66543.78000000","0.00000000"],["66544.54000000","0.00000000"]]}
{"e":"depthUpdate","E":1636513788885,"s":"BTCUSDT","U":5215106,"u":5215109,"b":[["66533.60000000","0.00751500"],["66532.00000000","0.00751
600"]],"a":[["66539.09000000","0.00751500"],["66542.77000000","0.00751400"]]}

what is wrong with “wss://stream.binance.com:9443/ws” ?

The above snippet is valid and correct.

The issue you encountered is most likely cause by networking or you are trying to access Binance services from a restricted IP.

Are you able to access the Binance API using the ping endpoint?
https://binance-docs.github.io/apidocs/spot/en/#test-connectivity

you are right , thank you !

I’m sorry to reopen this post, I would like to ask how you dealt with it after that, the vpn I use takes about 10 minutes to reconnect to receive data, but I can easily get data using testnet

I suggest trying out a different VPN,