title: How to make the client receive server sent event using Javalin?
body: <p>I am trying to implement a server client project which needs the server to send data to the client every 5 minutes with the client only asking in the beginning of connection. Server-sent events seem to be the go-to solution.</p>
  
  <p>I have tried to use the functions given in the Javalin Documents. I am able to receive a response with a simple get from the server. But I couldn't establish a sse connection. The code enters the lambda function in the server but the client does not receive anything. I am not sure if the client or the server, or even both have a problem.
  The only output we get from the codes below is "connected" on the server side. Thank you in advance.</p>
  
  <p>Code for the server</p>
  
  <pre><code>import io.javalin.Javalin;
  
  public class SimpleTwitter {
  
    public static void main(String[] args) {
  
      Javalin app = Javalin.create().start(7000);
  
      app.sse("/sse", client -&gt;{
          System.out.println("connected");
          client.sendEvent("message","Hello, SSE");
          client.onClose(() -&gt; System.out.println("Client disconnected"));
      });
  
      app.get("/", ctx -&gt; ctx.result("Hello World"));
  
     }
  }
  </code></pre>
  
  <p>Code for the client</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;body&gt;
  
  &lt;h1&gt;Getting server updates&lt;/h1&gt;
  &lt;div id="result"&gt;&lt;/div&gt;
  
  &lt;script&gt;
  if(typeof(EventSource) !== "undefined") {
    var source = new EventSource("http://localhost:7000/sse");
    source.onmessage = function(event) {
      document.getElementById("result").innerHTML += event.data + "&lt;br&gt;";
    };
  } else {
    document.getElementById("result").innerHTML = "Sorry, your browser does not support server-sent events...";
  }
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>