Pickle file and send via socket

S

S.B

Hello friends

Does anyone know if it's possible to pickle and un-pickle a file across a network socket. i.e:
First host pickles a file object and writes the pickled file object to a client socket.
Second host reads the pickled file object from the server socket and un-pickles it.

Can anyone provide a simple code example of the client and server sides?

Thanks
 
N

Nobody

Does anyone know if it's possible to pickle and un-pickle a file across
a network socket. i.e: First host pickles a file object and writes the
pickled file object to a client socket. Second host reads the pickled
file object from the server socket and un-pickles it.

Yes, provided that the socket is a stream socket (e.g. TCP, Unix), not a
datagram socket (e.g. UDP).
Can anyone provide a simple code example of the client and server sides?

Pickling via a socket is no different to pickling via a file. For a
socket, the .makefile() method will return a suitable file object.
 
D

Dennis Lee Bieber

This is *absolutely* possible.
Did you know that IDLE uses this very method when run in sub-process mode!
It must be emphasized that this is likely to only work on the local
machine... Passing a pickled file-object across the net to different
machine will likely fail.

It also will be impacted by the normal pickle restrictions (that a
different version of Python may not be able to unpickle the data).

I don't know enough to know if M$ Windows operates in the same
manner with regards to file objects.
 
S

S.B

Hello friends



Does anyone know if it's possible to pickle and un-pickle a file across a network socket. i.e:

First host pickles a file object and writes the pickled file object to a client socket.

Second host reads the pickled file object from the server socket and un-pickles it.



Can anyone provide a simple code example of the client and server sides?



Thanks

Lot's of conflicting answers :-(

Can anyone provide a simple code example?
 
S

S.B

Hi



Firstly I am a raw beginner at Python and I don't publish this code

as a good example of anything. It works for me on Ubuntu Linux 12.04 and

Python3.2



As usual I welcome constructive comments but I will be working on this

more to help me understand exactly what is going on



http://pastebin.com/iFzK7fuk SpaceTravellers.py

http://pastebin.com/TdqPwMGi NetworkPickler.py

http://pastebin.com/DF5DtYRZ NetworkUnpickler.py



lipska



--

Lipska the Kat: Troll hunter, sandbox destroyer

and farscape dreamer of Aeryn Sun

Thank you so much !
The examples are very helpful.
What happens if I have a regular text file I want to send via the network.
Do I need to read the file and then dump it into the "stargate" file object?
 

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,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top