title: How exactly does Server-Sent Events work?
body: <p>I am trying to get into the web push technology so I started looking around. I have basically found 2 technologies, that is Websockets and SSE. After ruling out Websockets because of lack of perl support, I wanted to try out the more native SSE-approach.</p>
  <p>Now, trying to get SSE to work is a real pain in the arse. Every documentation has conflicting information and there does not seem to be a general consensus on how SSE works. Some say hat you need an <code>&lt;event-listen src=&quot;events.pm&quot;&gt;</code> tag, others say you only need an <code>EventSource</code> JS object. Even with the EventSource object, I found around 4 possible implementations and none of them seem to work.</p>
  <p>Here is what I have. I have an <code>events.pm</code>, which uses mod-perl. If you call that file, it returns <code>data: I haz a websocket</code>. That is sent with the content-type <code>application/x-dom-event-stream</code>.</p>
  <p>The HTML and JS files have been rewritten so often with different implementations that I have given up on them. Can you guys please give me a working example?</p>
  <p>Also: I do not understand how you can send specific messages to the client. Sending a predefined message seems to be fine. However,  if I imagine a situation where someone sends me a message, I do not understand how exactly that information ('there is a new message for you') is transmitted to that exact browser that needs that information. Every post I found on this is vague at best.</p>
  <h3>EDIT</h3>
  <p>Basically, what I need is a way to say 'hey, are you allowed to get this notification? show me your id/session/token first!' on a per connected client basis. I wonder if it is at all possible with SSE.</p>