首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么我的客户端每10秒重新连接一次

为什么我的客户端每10秒重新连接一次
EN

Stack Overflow用户
提问于 2018-02-07 00:44:36
回答 1查看 243关注 0票数 0

正在尝试使用socketcluster在浏览器窗口之间交换事件。

在发送方,我有:

代码语言:javascript
复制
var options = {
      hostname: "myserver.com",
      secure: true,
      port: 443,
      connectTimeout: 86400000,
      autoReconnectOptions: {
                  initialDelay: 100, //milliseconds
                  randomness: 10, //milliseconds
                  multiplier: 1.5, //decimal
                  maxDelay: 60000 //milliseconds
              }
     };

// Initiate the connection to the server
var socket = socketCluster.connect(options);
    socket.on('connect', function () {
              console.log('CONNECTED');
                });

function sendTime() {
    var currentDate = new Date();
    var theId = document.getElementById("object_id").value;
    count++;
    console.log("id "+theId);
    socket.emit('identity1', { timestamp: currentDate, id: theId, counter:count});
}

然后在服务器上,我让worker发布一个新事件:

代码语言:javascript
复制
  socket.on('identity1', function (data) {
    count++;
    console.log('Handled identity1', data);
    scServer.exchange.publish('identity-' + data.id, data);
  });

在接收器端,我有:

代码语言:javascript
复制
    // Initiate the connection to the server
    var socket = socketCluster.connect(options);
    socket.on('connect', function () {
      console.log('CONNECTED');
      identityChannel = socket.subscribe('identity-' + document.getElementById("object_id").value);
      identityChannel.watch(function (data) {
        var theTime=data.timestamp;
        console.log('ID:' + data.id + ' TIME: ' + theTime);
        document.getElementById("data2").innerHTML = 'TIME: ' + theTime + 'COUNTER : ' + data.counter ;
      });
    });

在Chrome的js控制台中,我看到两端在10秒后,客户端连接被拒绝,如下所示:

代码语言:javascript
复制
socketcluster.js:678 Uncaught SocketProtocolError {name: "SocketProtocolError", message: "Socket hung up", code: 1006, stack: "SocketProtocolError: Socket hung up↵    at SCSocke…myserver.com/socketcluster.js:1392:10)"}
(anonymous) @ socketcluster.js:678
setTimeout (async)
SCSocket._onSCError @ socketcluster.js:676
SCSocket._onSCClose @ socketcluster.js:781
(anonymous) @ socketcluster.js:426
Emitter.emit @ socketcluster.js:4152
SCTransport._onClose @ socketcluster.js:1494
wsSocket.onclose @ socketcluster.js:1392
sender.html:26 CONNECTED

我发现当重新连接时,一些事件会丢失。

问:这正常吗?

问: 10s的限制可以调整吗?

EN

回答 1

Stack Overflow用户

发布于 2018-02-07 01:46:35

实际上,您必须设置GCP负载均衡器连接超时,而不是默认值10s。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48647946

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档