Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder4.news.weretis.net!dedekind.zen.co.uk!zen.net.uk!hamilton.zen.co.uk!reader03.nrc01.news.zen.net.uk.POSTED!not-for-mail From: Nobody Subject: Re: Pickle file and send via socket Date: Mon, 06 Aug 2012 17:11:56 +0100 User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.) Message-Id: Newsgroups: comp.lang.python References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lines: 15 Organization: Zen Internet NNTP-Posting-Host: 6737b8f4.news.zen.co.uk X-Trace: DXC=F6R_UBfgekBI>27fALHYIJf2FgniPJjgB=dR0\ckLKG@WeZ<[7LZNRFQ249]PgH\SFM2Z^cWRFGAK7URI][?AHVJ X-Complaints-To: abuse@zen.co.uk Xref: csiph.com comp.lang.python:26631 On Mon, 06 Aug 2012 06:32:13 -0700, S.B wrote: > 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.