how do I make django and tornado communicate with each other - django

I have a social networking kinda an app in Django and I wanna integrate real-time notifications and messaging functionality in my app.
my friends could build a tornado app but I wanna basically connect them together (my guess are I have to make a REST API correct me if I'm wrong)
how can I do these kinda tasks from Django
Authenticate automatically to a WebSocket(tornado) as I logged in my
django app
import all of my friends
send tornado signal to send notifications if the user didn't receive a message
things like that
how do I do stuff like that.
(BTW I don't wanna use django channels as it's fairly new)

You can use a message broker library like ZeroMQ or RabbitMQ to help them communicate with each other (The Django instance and the Tornado websockets component).
They provide several message architectures like server-client or publisher-subscriber.

Related

Using Django REST framework for real-time chat?

I'm trying create a real-time chat app with Django and Vuejs. I would like to use django-rest-framework for this but I don't know how to make it real-time. I have used django-channels before but I'm curious if I can use only django-rest-framework as an alternative or maybe integrated it with django-channels.
You don't have to integrate them, because django channels are sending and accepting json data to websocket, as your rest framework api does. Rest framework is made for api, django channels for websockets, they won't have nothing in common cuz they have different implementations. The only thing you could consider integrating is rest framework auth inside django channels see: How do you authenticate a websocket with token authentication on django channels?
I also am a beginner but from what I know.. rest framework isn't suitable for "real-time" working of web-application cause it can't make a 2-way connection (like.. send data to other memebers in group without them making a call to it) for this purpose django channels is a better medthod cause its making a websocket connection.
do let me know if i m wrong.

How are messaging apps like Whatsapp or Messenger built?

I'm trying to build a mobile messaging app like Whatsapp and don't know where to start. In the first place, I don't know how messaging apps send messages between users. What type of protocol do they use? Do they use websockets? Do they use some sort of long polling? I mean what I really want to know is how the server works and is there a name to this sort of communication?
FYI, I was looking to try and build a messaging app with a Django (something like django channels) server and React native for the mobile app.
Thanks for reading.
Yes to create a chat application like messenger or WhatsApp you will need to use websocket, also a cache like redis
If you want to create a chat backend with django and django channels you can follow this repository, this is pretty basic. You can use this repo to build a chat api, which you can use with a mobile app/desktop app as well as a web app
https://github.com/khan-asfi-reza/ChatAPI
This is a minimalistic Chat Api built with django, django rest framework, django channels.
And if you want something more extra like read/seen feature, this following repo will be best
https://github.com/Bearle/django_private_chat2
And for react native app, you can see the following repo, this codebase might be a bit complex for beginners
https://github.com/cometchat-pro/react-native-chat-app.git

Send notifications through DRF

Hello I'm building a RESTfull application using Django Rest Framework.
The clients are android application and react application.
I need to send a time based notification to users.
To send push notifications you can use the well supported https://github.com/jazzband/django-push-notifications app
It is not necessary to use FCM for android. I personally like to use Firebase Cloud Messaging (FCM). If you want to give it a try i suggest to use the pyfcm library https://pypi.org/project/pyfcm/
.
It's pretty straight forward and well documented. As for the authentication problems in the django-rest-framework, please be more specific.

How to implement websocket for push message using django-rest-framework as backend and angular2 as frontend?

I want to implement websocket to send push notification to client.
I am using django-rest framework as backend and angular2 as frontend.
I know that django support HTTP protocol only. And I am unable to get
any such links,blogs or resource which helps me to achieve websocket
completely.
Currently I am using polling from frontend.
There are some third party apps which I found and may be useful for
implementing push message. They are...
pywebsocket
tornado
Django Channels
I don't think showing some code is significant here because i have no
code relevent to implementation of websocket.
So can you people suggest me the best way to implement this thing.Any
link,any blog or any code which may help.
One possible solution is to deploy a separate Tornado app which communicates with Front-end using WebSocket. Then, whenever the Django Back-end wants to send a push notification to the Front-end, it asks the Tornado app and Tornado app delivers the push notification to Front-end.
I have described the process in slightly more detail in this answer of mine. You might want to have a look.

emitting Signal from server to the clients in Python Django like SignalR

I'm using Backbone.js and Python Django Combo.
For checking user is authenticated or not, I'm using setTime out method and call a method which make ajax call to the server.
I heard SignalR from my friend who is interested in .Net Technologies. This can emiting signal from server to client. So he say there is no need to poll periodically with signalR.
Any help or idea will be appreciated.
Possible data flow diagram:
.
If you want to control the data that is pushed to your web clients from your Django app, you will need to use SignalR as a relay of sorts which can be hosted with an ASP.NET app.
The ASP.NET app can have REST endpoints accessible only to your Django app, and can then from there based on the REST parameters push messages to some or all of your clients. Example of doing this with ASP.NET MVC.
The SignalR Wiki can be a good resource for this. You will also need to EnableCrossDomain for this setup to work.
If you don't like the idea of setting up another server just to push data to your clients you might prefer a cloud-based offering like Pusher with a prebuilt wrapper around their REST API.
If you want to use Python to actually push to the clients you can use something like tornado.websocket, but that won't support browsers that don't support the final WebSocket spec.