Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.016 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'wed,': 0.04; 'socket': 0.05; 'dictionary': 0.07; 'method,': 0.07; 'python': 0.07; 'roger': 0.09; 'am,': 0.14; 'wrote:': 0.14; 'simplicity.': 0.16; 'socket.': 0.16; 'code': 0.22; 'header:In-Reply-To:1': 0.22; 'trying': 0.23; 'foundations': 0.23; 'objects': 0.24; 'example': 0.24; "i'm": 0.26; 'chris': 0.27; 'object': 0.27; 'message- id:@mail.gmail.com': 0.28; 'hi,': 0.29; 'server': 0.29; 'functions.': 0.29; 'one,': 0.31; 'to:addr:python-list': 0.32; 'idea': 0.32; 'creates': 0.33; 'uses': 0.34; 'using': 0.34; 'file': 0.35; 'problem,': 0.35; 'received:209.85': 0.37; '20,': 0.38; 'apr': 0.38; 'strings': 0.38; 'received:google.com': 0.38; 'to:addr:python.org': 0.39; 'received:209': 0.39; 'how': 0.39; 'would': 0.40; 'header:Received:5': 0.40; '2011': 0.62; 'below': 0.63; 'worth': 0.64; '(based': 0.84; 'alexander': 0.84; 'received:209.85.210.174': 0.84; 'received:mail- iy0-f174.google.com': 0.84; 'subject:over': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=Hq2FgNxEzdUY6TzMoJNa/hPASZu6U73kl1ppyDASnPQ=; b=nFx2kmwk6K+W/q42oxMzc+WWsRM6oW5u/hyCEI53bzETZeZ7rHVDVt5JnvTU6JmQ1m nzmwu70Wbg1k/3aXkNxgpdZNLptdRS1+K2F9NTmHANvBl28ToJpUpq4Oq9EvtRzAH1S6 hB/vc+4h09/mJbjrjOprnX2vXZ3kZkofnGgko= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=vBHCCu9Anlsgy5pPKgcaU5Rl9qi4JqQHDb+tOzhVrbNRMdTmDPJ/fMXYCKwrV77T4r tVL7V8ABwSReLUJU0yatONA5/6jYEW8m4J+l+cc9Qm3+hr/UMWuyyV3TAZgmmz/RRxFS rr9O73++g5v/BcIaHRQljCUfGsHoFMClDlPm4= MIME-Version: 1.0 In-Reply-To: <61890800-f81a-4a1e-8905-a0237407f016@a21g2000prj.googlegroups.com> References: <61890800-f81a-4a1e-8905-a0237407f016@a21g2000prj.googlegroups.com> Date: Wed, 20 Apr 2011 05:29:36 +1000 Subject: Re: Pickling over a socket From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 21 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1303241379 news.xs4all.nl 81483 [::ffff:82.94.164.166]:37773 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:3584 On Wed, Apr 20, 2011 at 4:53 AM, Roger Alexander wrot= e: > Hi, > > I'm trying to understand how to pickle Python objects over a TCP > socket. > > In the example below (based on code from Foundations of Python Network > Programming), a client creates a dictionary (lines 34-38) and uses > pickle.dump at line 42 to write the pickled object using file handle > make from a socket. The server de-pickles with pickle.load =A0(line 24), > again using a file handle made from a socket. Whenever there's a problem, create simplicity. I would recommend not using the file-from-socket method, and simply using pickle.dumps() and pickle.loads() to pickle to/from strings; those strings can then be sent/received over the socket using standard recv/send functions. Also, Chris Rebert's idea is a good one, and worth trying. Chris Angelico