Advice on sending images to clients over network

F

Frank Millman

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
 
B

Bjoern Schliessmann

Frank said:
My question is, what is the best way to get the image to the
client?

IMHO, HTTP would be most painless. Either incorporate a little HTTP
server into your server application, or use a seperate daemon and
let the server only output HTTP links.
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.

See above -- you could also write your own HTTP server. Best using
Twisted or something of similar high level. Why make yourself work
developing such a system when somebody already did it for you?
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?

For minimum additional work, I'd use some lightweight http daemon,
like lighttpd ot thttpd. Then your server can pass links like
<http://yourserver.example.com/images/thingy1.jpeg> and the clients
can use well-tested standard library routines to retrieve the
image.

Regards,


Björn
 
P

Paul Rubin

Frank Millman said:
Any suggestions will be much appreciated.

Why on earth don't you write the whole thing as a web app instead of
a special protocol? Then just use normal html tags to put images
into the relevant pages.
 
P

Paul McNett

Frank said:
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.

I would put the images into a static web directory, either on the same
or different server. Then your main server just sends the url (or
relevant portion of the url, or list of all urls to download), and then
the client grabs the images from your image server using urllib.

Let Apache do what it's good at, instead of reinventing that particular
wheel.
 
P

Paul McNett

Paul said:
Why on earth don't you write the whole thing as a web app instead of
a special protocol? Then just use normal html tags to put images
into the relevant pages.

I believe he has a full desktop client app, not a web app. Believe it or
not, there's still a solid place for desktop applications even in this
ever-increasing webified world.

Use the right tool for the job...
 
J

Jorge Godoy

Paul said:
I believe he has a full desktop client app, not a web app. Believe it or
not, there's still a solid place for desktop applications even in this
ever-increasing webified world.

He's using wxPython and already has network connectivity to access the
database server.
Use the right tool for the job...

Yep... I also believe that a HTTP server is the right tool. :)
 
C

Calvin Spealman

I believe he has a full desktop client app, not a web app. Believe it or
not, there's still a solid place for desktop applications even in this
ever-increasing webified world.

Use the right tool for the job...

There is no reason that something being a "desktop app" means they
can't use HTTP instead of reinventing the protocol wheel all over
again.
 
P

Paul McNett

Calvin said:
There is no reason that something being a "desktop app" means they
can't use HTTP instead of reinventing the protocol wheel all over
again.

Absolutely! Which is why I recommended setting up an httpd to serve the
images...

I interpreted Paul Rubin's response to say "rewrite the whole thing
(client, server, everything) as a web app".

Cheers!
 
F

Frank Millman

Frank said:
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 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?

Thanks for all the responses.

The verdict seems unanimous - use http.

Thanks for pointing me in the right direction.

Frank
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top