Eventsource API:例外:300000毫秒内没有活动.重新连接 [英] Eventsource API : EXCEPTION: No activity within 300000 milliseconds. Reconnecting

查看:317
本文介绍了Eventsource API:例外:300000毫秒内没有活动.重新连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用eventSource API,并将addEventListener()添加到eventsouce中.事件源被激活直到仅45秒.我想保持连接状态,直到服务器将响应发送回客户端.

I am using eventSource API and added the addEventListener() to the eventsouce. The event source is activated till only 45 seconds. I want to keep the connection alive until the server send the response back to client.

现在,我收到以下异常消息,因为直到45秒,服务器都没有响应.

Now, I am getting the below exception because there is no response back from the server till 45 secs.

例外:300000毫秒内没有活动.重新连接.

请给我一些指示,以使连接保持活动状态/其他实现该连接的方法.

Please give me some pointers to make the connection alive/ any other approach to achieve it.

推荐答案

解决方案是定期发送数据,即使是空字节也可以正常工作,并且可以使连接保持活动状态.

The solution is to send data periodically, even null bytes work and will keep the connection alive.

如果无法建立连接,而您想重试连接,则可以使用例如设置为45秒的setTimeout.

If the connection can not be established and you want to retry connecting, it is possible to use setTimeout set for instance to 45 seconds.

建立连接后,请使用clearTimeout停止尝试.

Once the connection is established use clearTimeout to stop trying.

这篇关于Eventsource API:例外:300000毫秒内没有活动.重新连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆