Server-sent event does not work with jersey SSE

后端 未结 4 2049
无人共我
无人共我 2021-01-06 04:05

I am trying to use JavaScript SSE from Jersey. I have Following code in my resource. I am hosting on Java7 and Tomcat 7. I dont get any error. But I don\'t see data either o

4条回答
  •  没有蜡笔的小新
    2021-01-06 04:42

    The OutboundEvent.Builder.name method sets the value of the SSE event field. Therefore, it is not treated as a message and cannot be listened using the .onmessage handler. The solution is simply using the addEventListener method to register the listener method.

    This code should work with the Jersey sample above.

    
    

    I found this article to be useful to understand how the SSE works in the browser side: http://www.sitepoint.com/server-sent-events/.

提交回复
热议问题