Eventsource API : EXCEPTION: No activity within 30

2019-09-02 17:52发布

问题:

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.

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

EXCEPTION: No activity within 300000 milliseconds. Reconnecting.

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

回答1:

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

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.

Once the connection is established use clearTimeout to stop trying.