EventSource disconnects after first message

拥有回忆 提交于 2019-12-10 11:40:15

问题


A bit confused about EventSource behavior.

It connects well and stays connected until it receives first message.

As i send a data: something\n\n message, the connection is dropped and new one created.

Using Content-Type: text/event-stream header and the connection are recognized as a event stream and the inspector shows pending status.

As i said, everything works well until i send first message.

After this the connection are interrupted and new one created and message not sent to browser(at least the page not updated as it should).

My server and client code are exactly as here: http://www.html5rocks.com/en/tutorials/eventsource/basics/

This happens on any browser.


回答1:


Make sure your server code are not sending Transfer-Encoding header.

Or if it sending it, make sure it is not set to chunked.

EventSource behaves strange on chunked Transfer-Encoding

You may remove Transfer-Encoding header or set it to identity.

If that does not help, make sure your web server does not set that header to chunked.

If it does and you can not update its config, make sure your code are setting the header to identity(headers set by your code will override ones set by web server).

If you simply remove the header in your code, the browser will use one set by web server,
so make sure to set it to identity rather than remove.



来源:https://stackoverflow.com/questions/13590755/eventsource-disconnects-after-first-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!