Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问心跳是如何处理的? #4

Open
bad7890 opened this issue Aug 30, 2019 · 1 comment
Open

请问心跳是如何处理的? #4

bad7890 opened this issue Aug 30, 2019 · 1 comment

Comments

@bad7890
Copy link

@bad7890 bad7890 commented Aug 30, 2019

我看到在JS里面设置了

stompClient.heartbeat.outgoing = 30000;
stompClient.heartbeat.incoming = 0;

那在心跳超时或者出现啥网络问题的时候,是怎么检测到心跳异常呢? 是会直接调用啥方法吗?

@anlingyi
Copy link
Owner

@anlingyi anlingyi commented Sep 5, 2019

这两个属性如果不设置的话默认是每隔10000毫秒去发送心跳检测的(浏览器端使用的是 JavaScriptsetInterval 方法)。

this.heartbeat = {
    outgoing: 1e4,
    incoming: 1e4
};

我个人对于 STOMP 的心跳检测的理解:

首先客户端和服务器端需要事先约定好心跳检测的频率,客户端以这个时间频率去发送一条信息(发送的信息是换行符 \n)到服务端,如果服务端在这个时间频率内成功接收到了这条信息,则表示客户端的连接是正常的,否则表示客户端的连接已经断开了。

我讲的不太完整且片面,具体可以查看 STOMP 的相关文档:http://stomp.github.io/stomp-specification-1.1.html#Heart-beating

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.