views:

163

answers:

3

I am working on a project in python using pygame and pyro. I can send data, functions, classes, and the like easily. However, I cannot send a surface across the wire without it dying on me in transit.

The server makes a surface in the def __init__ of the class being accessed across the wire:

self.screen = pygame.display.set_mode(SCREENRECT.size, NOFRAME)

On the server, the screen prints as Surface(800x800x32 SW) but when retrieved by the client it is Surface(Dead Display).

Something to note though. I get a dead display when I use an accessor function to get my screen. If I use print Player.screen to get the variable I instead get what seems to be a pyro pointer to the screen: <Pyro.core._RemoteMethod instance at 0x02B7B7B0>. Maybe I can dereference this?

More than likely I am being thick, does anyone have some insight? Thanks. :)

+1  A: 

Generally speaking, you don't want to send a Surface (I'm assuming that a Surface is a device-dependent display) across the network. Most of the time, your client will be responsible for managing the drawing on its local Surface, and your server is responsible for telling the client what it needs to draw. A server may not even have a display that's capable of showing graphics!

Harper Shelby
+1  A: 

A pygame Surface is a wrapper around an underlying SDL surface, which I suspect can't be serialized by Pyro. If you want to copy its contents across the wire, you would be better off doing something like this:

  1. on the server use Surface.get_buffer() to get access to the underlying pixels.
  2. make a note of the Surface's dimensions, colour depth, etc.
  3. send the data obtained from steps 1 and 2 over the wire to the client.
  4. on the client create a new surface using the dimensions, colour depth, etc, from step 2.
  5. set the new Surface's pixels using Surface.get_buffer() and copying in the pixels from step 1.

Edit: It just occurred to me that I'm overcomplicating it. To serialise your Surface, use pygame.image.tostring(), and to reload it, use pygame.image.fromstring().

Rod Hyde
This might be exactly what I am looking for. I'll try to implement it tonight.
Morrowind789
A: 

Try pickling the object and send the file...

Sriram