Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'detect': 0.07; 'http': 0.09; 'means,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:()': 0.09; '(data': 0.16; 'closed.': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'services)': 0.16; 'subject:issue': 0.16; 'true:': 0.16; 'followed': 0.16; 'command': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; '(such': 0.24; 'server.': 0.24; 'script': 0.25; 'class.': 0.26; 'code:': 0.26; 'header:X-Complaints-To:1': 0.27; 'arthur': 0.31; 'writes:': 0.31; 'open': 0.33; 'older': 0.33; 'problem': 0.35; 'subject:with': 0.35; 'connection': 0.35; 'something': 0.35; 'case,': 0.35; 'but': 0.35; 'belong': 0.36; 'charset:us-ascii': 0.36; 'remote': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'new': 0.61; 'received:217': 0.63; 'total': 0.65; 'services': 0.66; 'here': 0.66; 'close': 0.67; 'connection.': 0.74; '"one': 0.84; 'datas': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: dieter Subject: Re: socket issue with recv() Date: Sun, 24 Aug 2014 07:59:34 +0200 References: <64392c10-28c5-4eee-93d2-7dd4edba56fe@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Gmane-NNTP-Posting-Host: pd9e0aca1.dip0.t-ipconnect.de User-Agent: Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux) Cancel-Lock: sha1:9sgH8SyeiMV8YogPF2uR2YBImxc= X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1408859988 news.xs4all.nl 2961 [2001:888:2000:d::a6]:56661 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:76923 Arthur Clarck writes: > ... > The problem I have now is the following. > I have a script to connect to some telecom service. > The script is forking (parent/child) > The child is only reading what comes from the remote server. > Here the problematic code: > > total = '' > while True: > data = s.recv(1024) > total += data > if (data == ''): > print 'remote site is closed' > s.close() > sys.exit() > > What is happening is that I got some datas from the remote site, > Something like 'Contacting BH: ...' > But directly followed by 'remote site is closed. Some services (such as older HTTP 1.0 services) are designed for "one command per connection" mode. This means, they answer a signle command and then close the connection. >From what you describe, your service might belong to this class. In this case, you would need to open a new connection whenever you detect that the old connection was closed.