【问题标题】:websocket send truncated string on Azure (app service)?websocket在Azure(应用服务)上发送截断的字符串?
【发布时间】:2018-10-01 12:07:58
【问题描述】:

我正在做一个简单的客户端-服务器应用程序,其中客户端将通过 WebSocket 连接向服务器发送命令,服务器将根据客户端的命令进行响应并将字符串返回给客户端。我已经测试了代码在本地运行没有任何问题,但是当我将服务器作为应用服务发布到 Azure 时,当服务器将字符串发送回客户端时,该字符串被截断为仅 3963 个字符(原始为 5006)。是 Azure 应用服务的限制吗?此问题仅在 Azure 上出现,在本地没有问题。

const ws = new Websocket({
httpServer: server,
autoAcceptConnections: false
});

const clients = [];

ws.on('request', (req) => {
const connection = req.accept('', req.origin);
clients.push(connection);
console.log('Connected ' + connection.remoteAddress);
connection.on('message', (message) => {
    const dataName = message.type + 'Data';
    const data = message[dataName];
    console.dir(message);
    console.log('Received: ' + data);
    var msg_sent = data;
    clients.forEach((client) => {            
        // Don't send the data back to the original sender
        if (connection == client) { // don't send the message to yourself
            //console.log(msg_sent.toString());
            // Execute every command with non-blocking
            var subMsg = msg_sent.toString().split('\0');

            for (var j = 0; j < subMsg.length; j++) {
                if (subMsg[j] == '')
                    continue;
                Command(subMsg[j], client);
                }
            //Command(msg_sent, sockets[i]);            
        }           
    });
});
connection.on('close', (reasonCode, description) => {
    console.log('Disconnected ' + connection.remoteAddress);
    console.dir({ reasonCode, description });
});

});

【问题讨论】:

    标签: node.js azure websocket truncated


    【解决方案1】:

    找到原因,服务器分块发送消息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-28
      • 1970-01-01
      • 2016-02-10
      • 1970-01-01
      • 1970-01-01
      • 2014-08-13
      相关资源
      最近更新 更多