简体   繁体   English

Node.js + ws - websocket意外关闭

[英]Node.js + ws - websocket is unexpectedly closing

I have a Node.js + ws server and a Qt client . 我有一个Node.js + ws服务器和一个Qt客户端 I'm having an issue with the websocket connection closing unexpectedly in certain conditions. 我遇到了在某些情况下意外关闭websocket连接的问题。 In my client, I iterate through a list of objects and send a series of requests to the server. 在我的客户端中,我遍历一个对象列表并向服务器发送一系列请求。 The server then accesses a database and then writes the response back to the client. 然后,服务器访问数据库,然后将响应写回客户端。 Here is the (simplified) basic server loop: 这是(简化的)基本服务器循环:

// ...

var httpServer = http.createServer(//params);
var WebSocketServer = require('ws').Server;
var wss = new WebSocketServer({ server: httpServer });

// ...

wss.on('connection', function connection(ws) {

  ws.on('message', function incoming(msg) {
    handleRequest(JSON.parse(msg), function (err, result) {
      if (err) throw err;
      ws.send(JSON.stringify(result), function ack(error) {
        if (error) throw error;
      }
    }
  });

});

If I limit the number of request from the client, everything works fine. 如果我限制来自客户端的请求数量,一切正常。 But if I reach a critical number of requests, data stops coming back from the server and the websocket connection times out. 但是,如果我达到了临界数量的请求,数据将停止从服务器返回并且websocket连接超时。

I'm wondering if I need to flush the websocket on the server before or after each write? 我想知道是否需要在每次写入之前或之后刷新服务器上的websocket? QtWebSocket has a flush() method, but I don't see this capability in the ws docs. QtWebSocket有一个flush()方法,但我没有在ws文档中看到这个功能。 Any ideas would be appreciated. 任何想法,将不胜感激。

UPDATE: I should also note that no errors are sent to either ws or wss . 更新:我还应该注意,没有错误发送到wswss Data just stops flowing. 数据停止流动。

UPDATE 2: Okay, this seems pretty clearly to be a problem with transmitting oversized packets from my client over the Internet to the node+ws server. 更新2:好的,这似乎很明显是通过Internet从我的客户端向节点+ ws服务器传输超大数据包的问题。 Based on Wireshark traces, once the oversize threshold is reached, the socket craps out, but only when I'm connected remotely to the server. 基于Wireshark跟踪,一旦达到超大阈值,套接字就会崩溃,但只有当我远程连接到服务器时。 If the server is on my local subnet, oversized packets are properly transmitted to the server. 如果服务器在我的本地子网上,则超大数据包会正确传输到服务器。 Any ideas how to debug this? 任何想法如何调试这个?

This problem resolved after I replaced one of my routers. 我更换了一台路由器后,此问题得以解决。 I am chalking this up to a hardware issue with the old router. 我正在解决旧路由器的硬件问题。 This was consumer-grade hardware, so I'm hoping this shouldn't be an issue in production. 这是消费级硬件,所以我希望这不应该是生产中的问题。 It does make me wonder how many of these kinds of bugs might be hanging out on the Internet... 它确实让我想知道有多少这类错误可能会挂在互联网上......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 StackExchange NetGain与Node.js WS Websocket服务器的性能 - StackExchange NetGain vs Node.js WS websocket server performance node.js ws:如何识别哪个websocket发送了消息? - node.js ws: How to identify which websocket sent a message? 使用ws和websocket-stream在node.js中流式传输数据 - Streaming data in node.js with ws and websocket-stream 防止 Node.js websocket 连接打开(ws库) - Prevent Node.js websocket connection from opening (ws library) Websocket 与 C# 客户端和 Node.js 服务器握手 - Websocket Closing Handshake with a C# client and a Node.js server 用户友好的关闭Node.js WebSocket连接的方式 - User friendly way of closing node.js websocket connections 将异步函数作为Websocket(ws)listerner传递可以吗? (node.js和ws库) - is it ok to pass asynchronous function as Websocket(ws) listerner ? (node.js and ws library) Node.js和Websocket服务器的Arduino WebSocket客户端连接问题 - Arduino WebSocket Client connection issue with node.js ws websocket server JS WebSocket无法连接到运行Node.js'ws'包的AWS EC2实例 - JS WebSocket won't connect to my AWS EC2 instance running Node.js 'ws' package 通过node.js和“ ws” -package了解基本的websocket API(API:bitfinex) - Understanding basic websocket API with node.js and “ws”-package (API: bitfinex)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM