Strope Status 断开后如何重新连接
我想让 Strope 在处于状态时自动重新连接 断开连接,我编写的代码如下所示:
if (status == Strophe.Status.DISCONNECTED) {
connection.connect(setting.userId, setting.password,
onReConnect, 3600);
}
但它不起作用。我该如何解决? 谢谢大家。
问候
I want make Strophe reconnect auto when it's Status
disconnected, I write code look like follow:
if (status == Strophe.Status.DISCONNECTED) {
connection.connect(setting.userId, setting.password,
onReConnect, 3600);
}
but it's not work. How can I resolve it?
Thanks everyone.
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里我使用的是openfire。不确定其他服务器,但在 openfire 中有一个名为 xmpp.httpbind.client.idle 的服务器变量。它是设定客户可以保持理想状态的时间段。默认值为30。如果理想时间超过给定值,服务器将自动终止连接。要么增加这个值,要么每隔一段时间发送一次心跳。它可以是一个简单的存在节。
我认为您还需要考虑一件事。出于安全原因,您不应将密码存储在任何 JavaScript 变量中,如果您错过了连接,最好尝试附加到现有会话。 Strope代码非常简单,只需使用connection.attach即可。
Here I am using openfire. Not sure about other servers, but in openfire there is a server variable called xmpp.httpbind.client.idle. It is to set the period of time the client could remain ideal. The default value is 30. If ideal time passes the the given value, server will automatically terminate the connection. Either you increase this value, or you send a kinda heartbeat every once in a while. it could be a simple presence stanza.
There is one more thing I think you need to consider. You shouldn't store password in any javascript variables, for safety reasons, it is better to try to attach to the existing session if you missed the connection. Strophe code is quite simple just use, connection.attach.