我已经使用webstomp-client从服务器获取某些更新(从服务器流式传输某些数据)。我在服务器端安装了Spring Boot。
服务器端配置:
sockJS:
streamBytesLimt: 4194304
serverHeartbeatMs: 5000
clientHeartbeatMs: 5000
stomp:
sendBufferSizeLimit:10485760
messageSizeLimit:5242880
sendTimeOut: 30000
在客户端,我与webstomp client有了角度的用户界面。 客户端代码如下:
stompClient.connect(
{} as any,
() => {
console.log("connected")
// some code
},
error =>{
stompClient.disconnect(() => {
setTimeout(() => {
this.connect();
},this.RECONNECT_TIME);
});
});
**大多数情况下都能正常工作,但是尽管网络连接良好,但有时连接也会失败。 **
事件顺序:=
1)For some reason request(xhr) doesn't go from webstomp client (checked in Network
tab of chrome)
2)Unless stomp client is connected, we dont send heartbeat.
3) when server realizes session is ideal for more than (60s), websocket
closes the session
4) Error block of webstomp client 's connection request gets executed.
5) Then I try reconnecting after disconnecting gracefully, And 1,2,3,4
continues until page is being refreshed.
浏览器日志: 错误代码:1006 错误:http状态为500(因为服务器因超过60秒的非活动状态关闭了会话,但有例外)