I'm building a websocket server in python and I've hit a block regarding my program's flow and structure. Here's what I'm doing at the moment.
- The program creates a instance of 'server' and listens on the port.
- The client connects to the server -- this creates an instance of 'connection' and passes 'server' as an parameter.
- The client sends a message to the server. 'connection' captures this. An instance of 'packet' is created, passing the message to it as a parameter. 'packet' unbusts the message (sometimes manipulating it).
- Based on the info sent in the message, 'connection' passes it to a different controller to be handled. The controller receives 'server' and 'connection' as a parameter so that it can send a response through 'connection', or many responses through 'server'.
My problem is that I feel like I'm treating this far too much like a web application (one request, one response), but I understand that server applications generally don't work like this - especially when it comes to websockets.
For example, person A could send a message to the server, which presents a prompt on person B and person C's screen.
What can I do to improve my application?