1
votes

I'm using this code to send an SSE message to the browser client.

https://nodejs.org/api/http.html#http_response_write_chunk_encoding_callback

Node server

    response.writeHead(200, {  'Content-Type': 'text/event-stream', 'Access-Control-Allow-Origin': '*' });
    response.write(message);
    response.end();

And for the client I'm using this javascript:

var source = new EventSource('myurl');
source.addEventListener('add', addHandler, false);
source.addEventListener('remove', removeHandler, false);

Everything is working fine, but how the server knows for sure that the client actually received it ? I guess SSE is using TCP, is there any way to received the acknowledgement ?

3

3 Answers

1
votes

SSEs are a one to many Push protocol. So there is no acknowledgement. You could send an AJAX request back on receipt, but there is nothing in the pattern to provide this functionality.

0
votes

SSE is a one way communication protocol to push data from server to client.

There no way for a client to ack event reception.

If acknowledge is a must have, you probably need a two way communication like websockets.

0
votes

I know this is many years old, but none of the answers is correct. 1) TCP does indeed ACK the push stream - its standard http! (though whether your code is at a low-enough level to detect it is a different story)

2) it's not to difficult to develope your own ACK system (I've done it! - To free up resources when last client disappears) and yes, it tends to go against the "spirit" of the protocol and duplicate to a degree the websocket paradigm...but it is wrong to say its impossible. Send a unique per-client "token" in the first message which the browser saves and starts a js "ping" timer which ajaxes a "still alive" message. In your erver code, handle the ajax and restart client-stil-alive timer. If that expires, client has gone, clean up / free resources etc.

Yes its a bit "lumpy" but it works and its not rocket-science difficulty.

just my (very late) 2c worth

The attached image was me diagnosing a case where the ACK was missing, but one every other one apart from the indicated one you can see the ACK enter image description here