Path: csiph.com!usenet.pasdenom.info!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!news.tele.dk!news.tele.dk!small.news.tele.dk!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '(b)': 0.07; 'socket': 0.07; 'subject:query': 0.07; 'back.': 0.09; 'formatting': 0.09; 'function,': 0.09; 'happens.': 0.09; 'mess': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; 'def': 0.12; 'assume': 0.14; 'wrote': 0.14; 'creates': 0.14; '23,': 0.16; 'above)': 0.16; 'bind': 0.16; 'disconnect': 0.16; 'fine.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'port))': 0.16; 'send()': 0.16; 'tcp': 0.16; 'tends': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'seems': 0.21; 'import': 0.22; 'cc:addr:python.org': 0.22; '(a)': 0.24; 'bytes': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; 'sort': 0.25; 'mention': 0.26; 'switch': 0.26; 'post': 0.26; 'somewhere': 0.26; 'header:In-Reply- To:1': 0.27; 'tried': 0.27; 'dec': 0.30; 'list:': 0.30; 'strongly': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'code': 0.31; 'lines': 0.31; 'posting': 0.31; 'usually': 0.31; 'request,': 0.31; 'terminate': 0.31; 'url:python': 0.33; 'maybe': 0.34; 'something': 0.35; 'beyond': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'google': 0.35; 'there': 0.35; 'done': 0.36; 'url:listinfo': 0.36; 'doing': 0.36; 'method': 0.36; 'url:org': 0.36; 'server': 0.38; 'pm,': 0.38; 'sure': 0.39; 'mailing': 0.39; 'url:mail': 0.40; 'issues,': 0.61; "you're": 0.61; 'first': 0.61; 'complete': 0.62; "you've": 0.63; 'such': 0.63; 'become': 0.64; 'more': 0.64; 'reply': 0.66; 'address,': 0.75; '(probably': 0.84; 'off,': 0.84; 'to:none': 0.92; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=OsGYizfbU1VeCBn45LOqATJD6dTVCE67cATbKJ7l7qI=; b=km6lLEmgdKMnXgSqXAixHls/AeMxFDCkTsfMtJ9emV2T5zAeqG02ZwY/zAOyizM7rM TJKeCIg4ESqcMuNL2HmJA5L/XhSbKfHxYerzsRbwA365WUS3ts+0G82qEdRJbIRa6AZD ddFHv8f5PjdC6tPvCdf82SSh3DQEofZPrIe98i5axVgRRCA7Fi5KtdPRQgn0n0sx+wG2 tEcpEFx12cwgBWsge/EzZuDjKh+s2lWDuCnsfUknf3w/G2VGkUVMO1GQYdRXM3c70jGT 6dWPwWKbtDjuAXtxpPBqMm1xw6Ib/EvzRNoBKbw4lYOzBPmFaNOVd9NMjmQntj7rvRkW Fx+A== MIME-Version: 1.0 X-Received: by 10.68.139.228 with SMTP id rb4mr22971107pbb.15.1387768770483; Sun, 22 Dec 2013 19:19:30 -0800 (PST) In-Reply-To: <3cea84e7-bfd5-4feb-b786-96a3501ffcf4@googlegroups.com> References: <3cea84e7-bfd5-4feb-b786-96a3501ffcf4@googlegroups.com> Date: Mon, 23 Dec 2013 14:19:30 +1100 Subject: Re: python socket query From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1387768779 news.xs4all.nl 2913 [2001:888:2000:d::a6]:33353 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:62582 On Mon, Dec 23, 2013 at 2:05 PM, wrote: > I wrote a small program which creates the socket, bind to the socket, connect to socket and send() close(). I see that there is no reply coming from server and the TCP disconnect happens. > import socket > > def tcp(host, request, port=34567): > > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > > s.connect((host, port)) > > s.send(request) > > reply = s.recv(2**14) > > s.close() > > return reply First off, your formatting has become mangled. This is likely to be because of Google Groups, which tends to make a mess of posts. I strongly recommend you get a better newsreader, such as Thunderbird, or switch to the mailing list: https://mail.python.org/mailman/listinfo/python-list I'm going to assume that (a) the code you've provided is all part of the tcp() function, and (b) that you are actually calling tcp() somewhere and seeing what comes back. But once you sort out your posting issues, you may want to post a complete program (probably not more than a couple of additional lines beyond what you have above) so we know what's actually going on. Terminology point: You mention binding to the socket. In networking, "bind" has a specific meaning - binding to an address, usually done for servers, and something you're not doing here. Are you sure the server's doing something? I tried what you had there (albeit under Python 3.3), and it seems to be fine. Perhaps you need to terminate the request with something - maybe a newline. The send() method will send exactly the bytes you give it, nothing more. Can you telnet to the server? ChrisA