server sent event

I have a question about server sent event.Client side I connect to server and close but I don't take data value.Here my javascript code what is the wrong please help me.

unction start() {

if (!window.EventSource) {
// IE or an old browser
alert("The browser doesn't support EventSource.");

var eventSource = new EventSource("http://localhost:8000/tms/generic/");
eventSource.onopen = function(event) {
log("Event: open");

eventSource.onerror = function(event) {
log("Event: error");
if (this.readyState == EventSource.CONNECTING) {
log(Reconnecting (readyState=${this.readyState})...);
} else {
log("Error has occured.");

eventSource.onmessage = function(event) {
log("Event: message, data: " +;


function log(msg) {
denemeh.innerHTML += msg + "
and My error ;
Uncaught TypeError: Cannot read property 'length' of undefined | TypeError: Cannot read property 'length' of undefined at Object.ProcessAccelerator

To what product does this related? This seems all plain JavaScript?

I want to update a specific field in continious scroll without refresh all the fields of continious scroll. Let me explain in a simple example. Think about facebook. When you'are in homepage you can see all your friend posts with its likes and comments numbers. If you add a comment in someone post then it will add that comment and increase the comments number at that moment without refreshing all the homepage. It will specifically refresh the certain post. So think that I've a website facebook/like. My homepage is based on continious scroll. That means all the posts will be shown in continious scroll. When I add a simple comment in a specific post then it does not update that post comment number at that moment until refresh all page. So how can I reach my goal in this case ? Can you give me proper informations ? Thanks in advance


Can you be more specific about your setup? I created a mock node server to test SSE with your code and it worked OK.

Where do you use exactly the JavaScript code that you included in your first post? Do you get events from your server outside of the client application (e.g. if you move your JavaScript snippet in a separate HTML file, does it work)?


First of all, thank you for your time. I spoke with Mr. Mehmet. In short, he tries to automatically send updates from the server to the client using server-side-events or push-events, whatever you want to call it.

His setup is as follows:

The server-side consists of multiple XData servers and Web Sockets for multiple usages. These work in a traditional way; the client asks, the server gives.

The platform will be used by a lot of users at the same time, and each user will frequently interact with the servers. As such, a lot of updates are made. Every user has to see the update which is made by the other users. In a way, it is possible let a user trigger an event on the server-side at the moment he performs an update, which will pass on the relevant information to the other users. But this is inefficient compared to the already-existing server-side-event method.

To conlude, he wants to push data updates from the server to the client based on time, e.g. every 5-10 seconds or so. The data needs to be catched on the client-side. I believe you have to connect just once, and keep that connection in order to make this all work.

Like I said earlier, on the server-side, there are XData and Web Sockets available, but if needed, he can make use of a Sparkle Server if it will be easier that way.

Which steps are needed to take in order to set such a system up? E.g. What components are needed on both client and server-side, how to connect them, and lastly, how to catch the data received.

Kind regards,

Fatih Dagdeviren


Thanks for explaining in detail.

WebSockets are already capable of 2 way communication. If it's a possibility to extend one of the WebSocket servers so that it periodically sends out a message to the connected clients (for example with a timer), then you can use TWebSocketClient component in your web client application to catch the incoming messages without SSE.

Would this be too demanding of your WebSocket servers or perhaps do you want to keep this somewhere separately?

If I understand correctly, SSE is nothing more than an HTTP server that:

  • Accepts incoming connections if the HTTP request header specifies that it can accept the event-stream MIME type
  • Stores these connections and listens for any connection drops, maintains a list of active connections accordingly
  • Periodically (or when something happens) it sends a message to the list of connected users, which can be detected and handled through the EventSource API from the first post on client side.

If you are looking for something like above, then it might be possible to do it with a TIdHTTPServer, you just need to make sure that the data you send is correcly formatted.