Handle request over TCP connection using django - django

I'm developing a server using django. There are numbers of devices that connect to this server and send request periodically. How can I handle these requests properly?

You'll probably want to look into django signals to setup webhooks to listen for certain things to call other things etc... signals was built to keep your app in sync with changes being made throughout. https://docs.djangoproject.com/en/dev/topics/signals/

Related

Flask - websocket doesn't work correctly in a real server

I've developed a WebApp with Flask, where different threads check a status and, if something changes they send a new json to the client. Then the client, with the javascript, can update the html page.
Running the app in my LAN, different clients connect and everything work correctly.
If I run the app on a real server (such as AWS, by using "flask run --host=0.0.0.0" ), the clients can connect and show the web page, but they don't receive the json sent by the socket of the webapp.
In the WebApp, a thread sends the new json by calling a function that uses:
socketio.emit('update', {'number': new_json_FE}, namespace='/test')
While the javascript receives this message (and does something) in this way:
socket.on('update', function(msg) { ....}
It is very strange that the clients connected in the LAN receive correctly all the json sent by the socket, while in the web not: they only receive the json when they connect to, and I have to upload the page (they don't receive the socket messages).
Can you help me?
Thank you very much!
I would advise against the use of threads like you have described for this situation.
Instead I would probably create a new program, StatusUpdater, that is always running and which is connected via socket to your Flask-SocketIO backend. When it finds a change in status it sends w/e signal or payload it needs to, through a socket, to the Flask-Socketio server. The SocketIO server upon receipt of this StatusUpdater payload can then send a broadcast to all connected clients notifying the client of the update.

Broadcasting messages to all web workers in Clojure

I'm writing a Clojure application that uses websockets to communicate with clients. The server sometimes acts as a sort of hub, getting a message from one client and that triggering sending a message to another client. If I have only one web server that's fine, but if I have two I run into trouble as clients might be connected to different servers.
I think the best way to deal with this would be for a web server to broadcast the message received to the other ones so all of them can react and notify the appropriate client. How can I do this? Any libraries that can help?
If it matters, I'm planning on hosting this in Heroku at first but I always want to leave the door open for self hosting.

How does django work with websocket server and webserver simultaneously?

I think I have some confusion in the understanding of websocket server and webserver.
So I followed the tutorial of django channels, where I created a little app that listens on a channel and returns some response.
At the same time, I can still serve webpages with normal view functions, so how does django do this magic so that it works without me modifying anything in the nginx server config?
The documentation mentions how this works:
It separates Django into two process types:
One that handles HTTP and WebSockets
One that runs views, websocket handlers and background tasks (consumers)
They communicate via a protocol called ASGI, which is similar to WSGI but runs over a network and allows for more protocol types. [...] probably Daphne

How to send frequent real-time server-side status update messages?

I have a web server that listens for jQuery keyboard events and I would like to send a string of the status for a set of keys to another domain for processing.
What technology/language/protocol is able to do this on the server-side?
It must be able to send the updated status message upon immediate change as listened for by keyboard events like arrow keys.
This is not a standard server <-> client updating but rather client > server > another server.
Can a WebSocket be used to create a server-side connection to a remote location, not a client?
https://en.wikipedia.org/wiki/WebSockets
What technology/language/protocol is able to do this on the server-side?
Any modern server side language can do it, node.js, c#, python, php. Just write your condition and make the request from your server as client.
Can a WebSocket be used to create a server-side connection to a remote location, not a client?
Of course! Your server can be a client like any other device. NodeJS example

Keeping connection open in Django without websockets

I have a mini computer that does not support websockets that I would like to receive push notifications from a server.
The issue is that after the client connects to the server, the server responds and then closes the connection. This makes it so the client has to continually reconnect to the server to get new information.
Is there a way using Django to allow the connection to be left open and then have the server publish data to the client?
Django is primarily a request/response framework and as such does not have support for real duplex communication.
Socket.IO is the de facto library that makes websocket-like functionality cross-browser (IE5.5+), using real websockets as a transport if the browser allows it, falling back to HTTP long-polling or whatever else if it doesn't. For various options on integrating Socket.IO with Django, read this.