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

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.

Related

What is this distributed communication model called (client-server-engine)?

I'm looking for a communication model that is constructed the following way:
One or more clients can connect to a server
One (chess-)engine connects to the server
The information flow is only one way, e.g if any client sends a message to the server, the server will forward the message to the engine. But if the engine responds, it should first send the respond to the server which forwards the response to the specific client.
Additionally, do you have any ideas or code examples on how to program that using c++ with boost/beast?

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.

Not able to connect Node.js/Socket.io Server from a Client using Websocket from a Unix System in a LAN

I have written a client application in C++ using websockets in Unix Environment trying to connect a Node.js/Socket.IO server running in a LAN connectivity. I found the server application is not responding at all. I tried a couple of other options from client side eventually getting no response from the server. Basically, i am trying to send a JSON object to the system running SocketIO server, but the client is not getting connected even if the server listens on to a Port.
Help, is really appreciated. Thank you.
Make sure following has been checked-
Server running and port is open (firewall) - Client is unable to connect the server
Url is correct - Client is unable to connect or url not exist
Listener code or receiving task is running - Client connected but when server send data to client, client didnot receive data
JSON format is correct and json data does not contain invalid character - client send data server but server did not received
Follow -
remove date if exists into msg for test purpose, use " to prepare JSON data, donot put / end of the url if not required. example-
1. Write url as ws://abc.com:8080/wsserver
2. JSON data as {"name":"myname","yourname":"indo","msg":"birthday"}

Handle request over TCP connection using 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/

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