Path: csiph.com!usenet.pasdenom.info!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; '16,': 0.03; 'subject:Python': 0.06; 'socket': 0.07; 'think,': 0.07; 'here?': 0.09; 'works.': 0.09; 'cc:addr:python-list': 0.11; 'jan': 0.12; 'thread': 0.14; 'blocked': 0.16; 'blocking': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'googled': 0.16; 'guessing': 0.16; 'loop.': 0.16; 'messy': 0.16; 'node,': 0.16; 'non-blocking': 0.16; 'sockets': 0.16; 'subject:between': 0.16; 'tcp': 0.16; 'wrote:': 0.18; 'library': 0.18; 'trying': 0.19; 'implementing': 0.19; 'thu,': 0.19; 'examples': 0.20; 'seems': 0.21; 'code,': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'am,': 0.29; 'nature': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'requests': 0.31; 'go.': 0.31; 'another': 0.32; 'moment': 0.34; 'maybe': 0.34; 'case,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'doing': 0.36; 'wrong': 0.37; 'sure': 0.39; 'read': 0.60; 'is.': 0.60; 'first': 0.61; 'back': 0.62; 'reach': 0.63; 'networking': 0.64; 'receive': 0.70; 'interest.': 0.81; 'end.': 0.84; 'of*': 0.84; 'to:none': 0.92 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:content-transfer-encoding; bh=IfI0cUcGj6Gys72SN0oHFHZ99lcjaZR/H/Qge5J4J2I=; b=ajgQr7Vxz52a4k1kWqEEG3AdJ5jjslrEDgYp/F8d37t408RTiA6h0Z0dkhfvGHMpQd v6Xt92wjwTgM0gkamZcONtlZgQpuHNZ+yo6tzZf9l5B8zI4nvzRDmUZAzbww0Bbtq/A9 NyaPivV9xcF1hftkwyLic/jaZrhS+XqDaZYUbSW2uROk7m86o/lhdcUFDQjzY0PDY8jp Tkh3La0Qy2kiZjnoOY10PwHVXUXk11+AykWLoGSEo8Bdzp69Y7+kz4WWc2OnhXChuZ5R 67Qt0GiQqDeLM/2dNcmVCaimWluxMQwGs0OxSccNlqswlS0Wd5EMYIeWueRjuU3BL3zN a6EQ== MIME-Version: 1.0 X-Received: by 10.66.118.71 with SMTP id kk7mr4409483pab.14.1389807603590; Wed, 15 Jan 2014 09:40:03 -0800 (PST) In-Reply-To: <1ea934d2-d48b-4857-aa4a-f4d24a9d8552@googlegroups.com> References: <1ea934d2-d48b-4857-aa4a-f4d24a9d8552@googlegroups.com> Date: Thu, 16 Jan 2014 04:40:03 +1100 Subject: Re: Communicate between Python and Node.js From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389807613 news.xs4all.nl 2899 [2001:888:2000:d::a6]:54567 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:64010 On Thu, Jan 16, 2014 at 4:12 AM, Manish wrote: > At first I thought to use the requests library to GET/POST data to node, = but I googled around and it seems lots of people think TCP sockets are the = way to go. I tried implementing my own using several examples I have found = online. It *kind of* works. It seems like I get blocked while trying to rec= eive data back in the recv() loop. I never reach the end. I'm not an expert= in sockets/networking, but maybe I'm not wrong in guessing it is because o= f the non-blocking nature of Node.js ? Do you need to use non-blocking sockets here? I think, from a quick skim of your code, that you'd do better with a blocking socket. Tip: Any time you have a sleep(1) call in your code, look to see if it's doing the wrong thing. In this case, I'm pretty sure it is. Sleeping for a second and then trying to read from a nonblocking socket seems like a messy way to just read until you have what you want. There's another thread happening at the moment about networking in Python. You may find it of interest. ChrisA