Advice on sending images to clients over network

Frank Millman frank at chagford.com
Sun Jul 22 05:14:26 EDT 2007


Hi all

This is not strictly a Python question, but as the system to which
relates is written in Python, hopefully it is not too off-topic.

I have an accounting/business application, written in client/server
mode. The server makes a connection to a database, and then runs a
continuous loop waiting for client connections, establishes a session
with the client, and responds to messages received from the client
until the client closes the connection. The client uses wxPython as
the gui. All the business logic is on the server - there is none at
all on the client side. It seems to be working quite well.

I now want to add the capability of displaying images on the client.
For example, if the application deals with properties, I want to
display various photographs of the property on the client. wxPython is
perfectly capable of displaying the image. My question is, what is the
best way to get the image to the client?

Assume that the images are stored in a directory on the server, or at
least accessible from the server, and that the database has a table
which stores the full path to each image, with the property id as a
reference.

My first thought was that the server would simply retrieve the path,
read the image, and send it to the client over the network, along with
all the other information. The problem with this is performance - I
may set up a page with 20 images to be displayed on the client, which
may take some time. I need the server to respond to client messages as
quickly as possible, so that it is ready to handle the next request.
The server is multi-threaded, so it will not block other threads, but
it may still result in sluggish performance.

My second thought was to send the path to the image down to the
client, and get the client to read the image directly. The problem
with this is that each client needs to be able to resolve the path to
the image directory. At present, all that the client requires is a
pointer to the client program directory, and a parameter giving it the
ip address and port number required to make a connection to the
server. It seems an extra administrative burden to ensure that each
client can access the image directory, especially if at a later date
it is decided to move the directory.

My third thought was to set up a separate 'image server'. It would be
another server program written in Python, listening on its own port
number, waiting for a client request for a particular image. It would
know where to find it, read it in, and send it to the client. Then all
the client needs to know is the ip address and port number.

It seems likely that a typical setup would start by storing the images
on the same machine as the database and the server program. If so,
there would be little difference between any of the above, as no
matter with method is used, the same machine ultimately has to read
the record from its own hard drive and send it down the network over
its own nic.

If at a later date it was decided that the volume of image handling
was slowing down the server process, one might well decide to move the
images to a separate server. In this case, I think that my third
option would make it easiest to facilitate this. You would have to
change all the client parameters to connect to a different server. Or
maybe not - thinking aloud, I could pass the 'image server connection
parameters' to the client from the main server once a connection has
been established. A second implication is that you would have to
change all the paths in the database table. Again, maybe not - just
store the file names in the table, and the path to the directory as a
separate parameter. Then you only have to change the parameter.

I guess the point of all this rambling is that my thought process is
leading me towards my third option, but this would be a bit of work to
set up, so I would appreciate any comments from anyone who has been
down this road before - do I make sense, or are there better ways to
handle this?

Any suggestions will be much appreciated.

Thanks

Frank Millman




More information about the Python-list mailing list