I am trying to understand how to use websockets correctly and seem to be missing some fundamental part of the puzzle.
Say I have a website with 3 different pages:
- newsfeed1.html
- newsfeed2.html
- newsfeed3.html
When a user goes to one of those pages they get a feed specific to the page, ie newsfeed1.html = sport, newsfeed2.html = world news etc.
There is a CoreApplication.py that does all the handling of getting data and parsing etc.
Then there is a WebSocketServer.py, using say Autobahn.
All the examples I have looked at, and that is alot, only seem to react to a message from the client (browser) within the WebSocketServer.py, think chat echo examples. So a client browser sends a chat message and it is echoed back or broadcast to all connected client browsers.
What I am trying to figure out is given the following two components:
CoreApplication.py
WebSocketServer.py
How to best make CoreApplication.py communicate with WebSocketServer.py for the purpose of sending messages to connected users.
Normally should CoreApplication.py simply send command messages to the WebSocketServer.py as a client. For example like this:
CoreApplication.py -> Connects to WebServerSocket.py as a normal client -> sends a Json command message (like broadcast message X to all users || send message Y to specific remote client) -> WebSocketServer.py determines how to process the incoming message dependant on which client is connected to which feed and sends to according remote client browsers.
OR, should CoreApplication.py connect programatically with WebSocketServer.py? As I cannot seem to find any examples of being able to do this for example with Autobahn or other simple web sockets as once the WebSocketServer is instantiated it seems to run in a loop and does not accept external sendMessage requests?
So to sum up the question: What is the best practice? To simply make CoreApplication.py interact with WebSocketServer.py as a client (with special command data) or for CoreApplication.py to use an already running instance of WebSocketServer.py (both of which are on the same machine) through some more direct method to directly sendMessages without having to make a full websocket connection first to the WebSocketServer.py server?