How can I implement a system that can “push” messages to clients when necessary?
Basically, what I need is the ability to “push” text to Python clients from a Python server. The text will then be parsed to actions that will take care at the client side (I already know how to do this thing, once an ‘action-text’ is received).
I can check every couple of seconds for new ‘action-texts’ that are waiting — it’s just I don’t think it’s reliable and scalable to thousands of clients. The real-time thing is very important here.
Any suggestions, please?
I’d suggest having each client establish a socket connection to the server. Each client can run a thread that attempts a blocking read from the socket (put it in a background thread) that pulls information off the socket when it’s available. Then, whenever the server writes to that socket the client should get it immediately. The client’s connection should subclass
telnetlib.telnetimho, because it provides a convenientread_untilmethod. Something like this maybe: