I am new to network programming but old to Python. I have a simple blotter program that is to be used on multiple client computers. The blotter works two ways, it can show and update the information in the database. To avoid any blotters showing old data, how can I make all blotters re-fetch information from the database as soon as another blotter has updated some data in the database?
I would rather like to avoid complexity in setting up some client-server protocol. Is it possible to create some form of client-only protocol where a simple refresh message is passed along straight to the other blotters when they need to update their information?
To receive messages (e.g. the UDP package suggested by the other poster or an http request), the clients would have to run a basic server on the client machine. You could use the Python xmlrpc module for example. However, a local firewall may block the inward communication.
The easiest solution, if the number of clients is moderate, will be to frequently poll the database for changes: add a column "last modification time" to your drawing table and have the clients check this field. This way the clients can find out whether they need to reload the drawing without wasting too many resources.
Edit: The last modification field could either be actively updated by the client that made a change to the drawing, or automatically updated by a database trigger.
You could use triggers. When an information is updated send a signal (is up to you choose how, maybe just an udp packet) to all blotters that will update their information consequentially. Postgresql could be scripted using python.
精彩评论