How github auto updating comments work? - django

As mentioned here
https://github.com/blog/1174-auto-updating-comments
What is the technology behind this? If I've to add this feature in a Django powered web app, what should I use and study?

Looking at network tab it looks like they (at least with chrome) are using HTML5 Server Sent Events.
So practically the browser subscribes to a event stream and the web server just sends messages back.
I am not an expert but I guess on the server side you need to be able to keep an open connection that streams the events to the client.
I found an implementation of SSE for python here: https://github.com/niwibe/sse and a django implementation on top of that: https://github.com/niwibe/django-sse
I did not use them (yet) on any production so I suggest them only as study / poc material :)

Related

Live notification/chat in django

I am making a website with django now and I want to implement a live notification feature like the one on facebook or SE.
I did some research and it seems although there's two options: ajax long polling and websockets, the latter is the way to go.
However, as you know the go to plugin for websocket 'socket.io' turns out to be a node.js plugin and the django port only seems to support python 2 and the project seems pretty much dead. I am using python 2.7 as my project interpreter but I want to future proof myself so that if I upgrade to python3 later, I don't find myself not being able to use this functionality.
So my question is this:
Is there a straight forward and future ready way to implement websocket which will be used to send live notifications and chats in django env?
Django itself is build in blocking manner, i.e. with synchronous approach. So, you cannot open persistent websocket with django app, as it will block entire django thread.
If you want to enable notification/chat within django project environment, i would recommend to use centrifuge. It is written in python, but async (non-blocking) framework is used: tornado.
But, you don't need to even know how it works, as it provides simple REST api to communicate with it.
Simplified workflow, check docs for more details:
Start centrifuge at same server, as your django project (or on another but with low latency between them)
Your front-end will open websocket with centrifuge, not with django project.
When you need to send notification, send it to centrifuge from django via REST api, and centrifuge will deliver it to needed clients!
I've already tried it and it works!
Django doesn't provide what you're looking for out of the box. You'll have to use a third party library. One that works across frameworks is Pusher.
I think you must go for Firebase it gives you awesome synchronization and any how you are going to use chat on frontend so its does not have to do anything with django environment so you can update you backend asynchron in callback with firbase. Also firebase with AngularJS provides you really really awesome three way binding.

Two way communication using AJAX from an HTML page to a C++ application running in same server

Is it possible to communicate from a web browser(Loaded an HTM page from server) to an application running in the same server using AJAX. Need to send the request from browser using a button click and update the page with responses received from one another application running in the same server machine?
I am using HTML pages to create website and not using any PHP or ASP like server side scripting. In server machine data are manipulated using a C++ application.
I think you can use any sort of Javascript functions to do that. But you might need to use jQuery or similar frameworks to make your live easier. You might need to search for "Comet Programming" to know exactly how to do 2-way communication between client and server
Updated:
Well, this kind of stuff requires you to read a lot (if you have not already known). Basically, what you need is a server that can do long-polling (or eventsource, websockets). There are many open-source ones that might help you to get started. I can list a several good ones here. There are a lot more
http://www.ape-project.org/
http://cometd.org/
http://socket.io/
http://code.google.com/p/erlycomet/
http://faye.jcoglan.com/
So after you have the comet server up and running you will need to setup the client side (probably Javascript). For those listed projects, most of them come with the client side code to interact with the server (Except for erlycomet). Therefore, you can just use the examples provided and run a quick prototype. If you want to use your raspberry pi, you can use nodejs which provide a lot of ease for dealing with real-time communication (socket.io, faye). And lately, http://www.meteor.com/
I would think of the problem this way: you want to provide a web front end to an existing c++ application. To achieve this you need to think about how your web server communicates with your c++ application. Communication between the browser and web server can be thought of as a separate problem - as you say AJAX calls can be used, or maybe have a look at websockets.
Once you have your request in the web server you need to communicate it to the C++ application (and/or visa versa). This can be done a number of ways, e.g. sockets or RPC. I found this question here which has some good advice.

Django Comet/Long Pollling application

I am working a real-time lighting control system.
User can turn on/off lights through web interface, but when another person turn on/off light switch manually the web interface should be updated immediately. That's the real-time goal I want.
The structure of the system is like this.
I have my own server at home, which control/monitor light status real-time. Django project is on my cloud server communicating with my home server real-time.
I have searched some similar posts and found many tools that confuse me a lot. All I want is to do long polling. User's browser will send http request to django server periodically(say 30s). If nothing comes up, server will hold the response until next one come. If there is an event, server will just reply immediately so real-time change at the browser side.
I know websocket is a better way, but I just want to make it work, the simpler the better. As long as it's reliable, compatible with existing browsers, performance is not a primary concern for me now. I can change it later if there is performance issue when scaling up. If it's possible, I still want to use Apache server to do this.
Does anyone knows a good tutorial or example that shows me how to implement it?
Thanks so much
I use Django 1.4, wsgi, Apache.

ColdFusion and Streaming APIs... (i.e. Twitter)

Has anyone had any luck using ColdFusion as a way to collect data via streaming APIs?
i.e. - https://dev.twitter.com/docs/streaming-api
I know the best option is to use an app that literally sits on the server monitoring these portals. Just curious if anyone has done anything using CF yet.
Aaron Longnion built refynr.com using CF9. It's a service that collects users' Twitter streams based on supplied criteria. I imagine he's down something like you describe.
However, I'd look into the new web socket functionality built into ColdFusion 10 and see if that makes consuming streaming APIs any easier.
http://labs.adobe.com/technologies/coldfusion10/
If you know a bit of Java, it may not be too difficult to use Twitter4J, and build an event gateway for your CF app to consume the stream.
If you want to go the web socket route, see: Twitter + HTML5 webSocket API

Ajax Push written in C/C++?

I have existing chat server code written in C/C++ that communicates over TCP/IP with client installed GUI. I'd like to also allow "web" access to this functionality, where users can simply go to my website, have it display a nice basic HTML5 driven GUI, and have them interact with my chat server code and other users.
So: backend written in C, frontend HTML5 website that updates to clients immediately via Ajax Push. Is there some kind of C library I can use to achieve this? I would also accept a solution using technology that isn't Ajax Push as long as it functions how I describe. Note that I want to extend to be more data/traffic than simple chat, so I want this as close to realtime as possible.
I understand that APE (server) allows you to do stuff like this, but you have to write your backend in javascript? Is there a way to easily 'glue' it to a C/C++ server via pipes or something?
I'm working in Linux..
I may have misunderstood your question, but this sounds like what you're looking for: http://www.webtoolkit.eu/wt