data push using django - django

I'm interested in doing data-push from django to flex, can this be done using pyamf (tutorials or examples are highly appreciated)?
I would like to do it in such a way that when something is changed in the database, the client are notified of that change.

I haven't done it, and it looks difficult.
What does BlazeDS Livecycle Data Services do, that something like PyAMF or RubyAMF not do?
PyAMF gives you the tools to send and receive AMF messages in Python.
But Django isn't suited to push, as normally for push you'd use socket connections rather than HTTP.
Which probably means having a Twisted server as well. You could still use Django... you'd maybe have signals code in your models telling the Twisted server to send a message back to the Flex client.
You'd still have to write all the data-binding type code yourself on the Flex side, though PyAMF provide example client code to get you started.
Apparently the Java frameworks for Flex do code generation for both sides, making it all much easier.

Related

Clojure + stomp + websockets

I have followed a couple of tutorials about interactive/real-time applications using STOMP over WebSockets with the Spring framework using the messaging layer.
Example in Spring
I would like to implement the same functionality in clojure. Has anybody experience in implementing a similar application? I have been looking for documentation/examples about using these technologies, but there is nothing like the examples in clojure.
That it makes sense? Is it necessary to have an external message broker to connect the backend app and the browser clients?
I have some experience using a broker to pass messages along. However, I think it's still best to write your own http frontend for the browser to talk to. That frontend in turn can post messages to a broker (using Stomp or any other protocol). That way, you have more control and you're not tied to a message broker. For instance you can have the frontend do more than just websockets, like serve static files, or a regular HTTP interface.
But that's up to you, if the broker supports websockets, you can use that too (see for instance ActiveMQ). My advice is: try the simplest possible way first :-).
Take a look at Http-kit for a good Clojure webserver. It also has good websocket support.

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.

How to use NowJS to provide notifications to user in django framework

I have built a website in django framework. It has a lot of features such as blog, discussion forum, basically there are lots of ways users can interact. I have built a basic notification framework where a user gets notified when somebody comments on their blog, or answers their question in the forum.
Since the notifications are stored in db, new notifications are displayed only when a page refresh is done. I would like to make it real time using some push server using something like long polling technique.
I have come across NowJS which seems to be pretty handy for this, but in all the examples that are given I could not see any example where there was any interaction with the database. In all the cases there was some information sent by one client and it was displayed to one or more clients.
What I actually want to do is to call a function using NowJS, and make it go to sleep until a new notification is added in the database. When a new notifications comes in the server responds back with the notification and a new request is done immediately.
I can figure out all other parts except how to access the database from Node server that is used by NowJS. Any help or guidance is appreciated.
Either:
Have your node.js server make an http call to the Django server via something like a REST api to get info back
Google for a database connector for node.js - I found enough evidence for a MySQL one, and rumours of a PostgreSQL one. Note this won't get you access to the Django DB API, so you'll have to work out all your related queries and craft your SQL by hand (make sure Bobby Tables doesn't bother you: http://www.xkcd.com/327)
Re-implement the NowJS protocol so that you can write a django server for it, keeping the same JS client code on the clients... but then you may as wel.....
...use django-socketio http://blog.jupo.org/2011/08/13/real-time-web-apps-with-django-and-websockets/

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