正在尝试使用socketcluster在浏览器窗口之间交换事件。
在发送方,我有:
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发布一个新事件:
socket.on('identity1', function (data) {
count++;
console.log('Handled identity1', data);
scServer.exchange.publish('identity-' + data.id, data);
});在接收器端,我有:
// 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秒后,客户端连接被拒绝,如下所示:
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的限制可以调整吗?
发布于 2018-02-07 01:46:35
实际上,您必须设置GCP负载均衡器连接超时,而不是默认值10s。
https://stackoverflow.com/questions/48647946
复制相似问题