title: Server sent events + Java with Spring MVC
body: <p>I am currently having a problem related to SSE and Windows XP. The source code below is currently working in every Chrome I tried except for Chrome in Windows XP (?) Not sure why. This is intended to be used for a control panel, where users <strong>must</strong> use Chrome. In other words, I don't care about IE, Firefox, etc.</p>
  
  <p><strong>The problem</strong>: Server side events works everywhere (Chrome) but not in Windows XP (Chrome). <strong>When I say it works, I mean that the message handler is called.</strong></p>
  
  <p><strong>The code</strong></p>
  
  <ul>
  <li><p>Javascript code</p>
  
  <pre><code>if (!!window.EventSource) {
     console.log("Event source available");
     var source = new EventSource('/admin/systemalert');
  
     source.addEventListener('message', function(e) {
          console.log(e.data);
     });
  
     source.addEventListener('open', function(e) {
          console.log("Connection was opened.");
     }, false);
  
     source.addEventListener('error', function(e) {
          if (e.readyState == EventSource.CLOSED) {
              console.log("Connection was closed.");
          } else {
              console.log(e.readyState);    &lt;-- in windows XP it prints Error here
          }
     }, false);
  } else {
          console.log("No SSE available");
  }
  </code></pre></li>
  <li><p>Server side code</p>
  
  <pre><code>@Controller
  @RequestMapping("/admin/**")
  public class AdminController {
  
          @RequestMapping("systemalert")
          public @ResponseBody String sendMessage(HttpServletResponse response) {
                  Random r = new Random();
                  response.setContentType("text/event-stream");
                  try {
                          Thread.sleep(10000);
                  } catch (InterruptedException e) {
                          e.printStackTrace();
                  }   
                  return "data:Testing 1,2,3" + r.nextInt() +"\n";
          }
  
  }
  </code></pre></li>
  </ul>
  
  <p>As stated in the code, the line console.log(e.readyState); prints "Error" when using Chrome in Windows XP. Any ideas? Anyone see anything wrong with the source code?</p>
  
  <p>Thanks in advance.
  Agustin</p>