SSE (server sent events) server response handling

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



SSE (server sent events) server response handling



I have set up some server sent events basically to listen for new messages. I create a connection with an EventSource in the browser which makes a request to the server. My server response is the following:


res.writeHead(200,
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive'
)



The Problem is that my server will give a timeout error when there's no "full response" received within 50s...



The only workaround I found until now is to send a "ping" event every 50 seconds to tell that the connection is still alive like this:


sendPing()
function sendPing()
setTimeout(function()
res.sseSend(null,'heartbeat') //this simulates an actual event
sendPing()
, 50000)



Is that a good idea? A bad idea? Is there a better solution? Will this cause any problems in a single threaded application?



Thank you so much!





That shouldn't be needed. Do you have intermediate proxy servers that might instead be closing the connection? If not, can you give the full (but minimal) server code that will reproduce the problem?
– Darren Cook
Aug 10 at 20:52









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard