Communicate between Python and Node.js

Chris Angelico rosuav at gmail.com
Wed Jan 15 12:40:03 EST 2014


On Thu, Jan 16, 2014 at 4:12 AM, Manish <gill.manish90 at gmail.com> 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 receive 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 of 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



More information about the Python-list mailing list