HTTP Streaming/Push Notifications/Server sent event

Caporegime
Joined
18 Oct 2002
Posts
32,623
I don't know much about web technologies so looking for some pointers.

I had to create a website which displays realtime dynamic data. Because of my basic knowledge of web design and tight time constraints I simply developed a polling based solution in JS (doing a request every second).

This is fairly inefficient, ideally I would like an event based solution where the server pushes any state changes to the client but of course standard HTTP and web is based on individual requests with server and client disconnects.

I did think of having the server pause when receiving a request and only responding when the event occurs but this seems hacky and I don't know how the client JS likes having the request hang (I assume it will time out).


My research points to lots of external systems/plugins like active X but we really need to keep this to JS and available for mobile platforms and different browsers (at least chrome+ firefox).

I wrote the server in python using cherrypy to save time and will be re-writing the server in C++/apache
 
Caporegime
OP
Joined
18 Oct 2002
Posts
32,623
Sounds like a perfect task for Node.js.

You can write the server in js and use sockets. The client can just send a request to open a socket on the server and then subscribe to certain events. Then the server will just send the events to the client when necessary. No overhead over creating extra http requests. You can use something like knockout.js to update your client view when it gets any new data.

Everything in node is asynchronous (although you can use synchronous functions) so there's no 'hanging'.


Not really an option. The server relies on a huge c++ backend (around 10 engineer years spent in developing the code base which is used in different applications) and does a lot of heavy number crunching. The current server is really just a python wrapper to th C++ core using boost python. Due to performance reasons we will be removing th python layer and want the server to run in clean c++.

Is there something similar to node.js which can be used natively in C++?
 
Last edited:
Caporegime
OP
Joined
18 Oct 2002
Posts
32,623
WebSockets and then whatever for the backend; plenty of frameworks around for most languages. Only real issue you need to think about is browser fallback (to polling) - some frameworks have it built in for client-side; otherwise you'll need to implement it yourself.

Thanks, looking into this: libwebsockets.org

Brain us too fuzzy at the moment but will look into tomorrow.
 
Back
Top Bottom