Skip to content Skip to sidebar Skip to footer

Server Sent Event Not Working In Google Chrome

This is my server JSP code 'Server_Date.jsp' <% response.setHeader('cache-control', 'no-cache'); response.setContentType('text/event-stream'); out.print('data: ' + (new java.ut

Solution 1:

For one you are calling a function begin() that is not defined although that should not be the issue here.

Does the Chrome development console show any errors? It should show at least one. because of the begin function. And does the network tab show traffic to Server_Date.jsp?

Solution 2:

I used to have the same issue. As server part, I used PHP, but I guess it works the same. What fixed it for me was adding ob_flush(). Now, I don't know what it should be in your language, but maybe it helps you in the right direction.

Solution 3:

I've met the same problem, and i resolved it by add a newline at the end of the servlet. like this:

response.setContentType("text/event-stream;charset=UTF-8");
response.addHeader("Cache-Control", "no-cache");
PrintWriter out = response.getWriter();
out.println("data: " + new Date());
out.println();
out.flush();
out.close();

Solution 4:

Problem was solved

Solution :

Page encoding problem : client side used UTF-8 Encoding

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

Server side UTF-8 was not mention, so after adding charset=UTF-8 in setContentType its working

response.setContentType("text/event-stream;charset=UTF-8");

Thanks for people take your effort to answer my question

Post a Comment for "Server Sent Event Not Working In Google Chrome"