当我在nodejs中连接binance WebSocket时出现错误,我如何解决这个问题

7hiiyaii  于 11个月前  发布在  Node.js
关注(0)|答案(1)|浏览(149)
const WebSocket = require('ws');

const ws = new WebSocket('wss://stream.binance.com:9443/ws/btcusdt@trade');

ws.on('message', function incoming(data) {
    console.log(data);
});

字符串
这是我的代码,当我运行这个给定的错误

node:events:493
      throw er; // Unhandled 'error' event
      ^

Error: write EPROTO 885B0000:error:0A00010B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:355:

    at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:94:16)
Emitted 'error' event on WebSocket instance at:
    at emitErrorAndClose (C:\Users\uchun\node_modules\ws\lib\websocket.js:1033:13)
    at ClientRequest.<anonymous> (C:\Users\uchun\node_modules\ws\lib\websocket.js:880:5)
    at ClientRequest.emit (node:events:515:28)
    at TLSSocket.socketErrorListener (node:_http_client:495:9)
    at TLSSocket.emit (node:events:515:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -4046,
  code: 'EPROTO',
  syscall: 'write'
}

Node.js v21.1.0


我尝试了一切,但没有结果。

dzjeubhm

dzjeubhm1#

首先更新WebSocket并尝试以下操作:

const ws = new WebSocket('wss://stream.binance.com:9443/ws/btcusdt@trade',{
  rejectUnauthorized: false, 
  secure_protocol: 'TLSv1_2_method'
});

字符串

相关问题