Home > OS >  Problem in communicating with Binance exchange in NodeJS web socket
Problem in communicating with Binance exchange in NodeJS web socket

Time:08-10

When I execute the following piece of code in the app.js file

const WebSocket = require('ws');

const ws = new WebSocket('wss://stream.binance.com:9443/ws/!miniTicker@arr');

ws.on('message', function (data){
    //const result = JSON.parse(data);
    console.log(data);
});

I get the following error and I cannot receive data.

enter image description here

CodePudding user response:

10.10.34.34 (what your DNS server resolved stream.binance.com to) is a local IP address! You are not even reaching Binance. It's probably a captive portal or some firewall.

Open that IP address in the browser and check whether you get some sort of web interface that gives you a clue about what is blocking your request. You can also try changing your DNS server to Google (8.8.8.8) or some other public DNS server instead of relying on your router.

CodePudding user response:

When I tried again, the same error was displayed with IP address 148.251.160.243

PS C:\wamp64\www\Node> nodemon app.js
[nodemon] 2.0.19
[nodemon] to restart at any time, enter `rs`
      throw er; // Unhandled 'error' event
      ^

Error: connect ETIMEDOUT 148.251.160.243:9443
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16)
Emitted 'error' event on WebSocket instance at:
    at ClientRequest.<anonymous> (C:\wamp64\www\Node\node_modules\ws\lib\WebSocket.js:635:10)
    at ClientRequest.emit (node:events:520:28)
    at TLSSocket.socketErrorListener (node:_http_client:442:9)
    at TLSSocket.emit (node:events:520:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -4039,
  code: 'ETIMEDOUT',
  syscall: 'connect',
  address: '148.251.160.243',
  port: 9443
}
[nodemon] app crashed - waiting for file changes before starting...
  • Related