

Python socket programming tutorial - silv3r_m00n
http://www.binarytides.com/python-socket-programming-tutorial/

======
peter_l_downs
If you want to understand sockets, there's no excuse for not reading Beej's
Guide to Network Programming [1]. It's C, not Python, but it covers all of the
dirty details and explains _exactly_ what's going on when you create a socket.
For instance, this article never mentions that sockets are file descriptors —
in Beej's article, it's right after the introduction (Section 2 [2]).

How does this article describe a socket?

    
    
        > sockets are the fundamental "things" behind any kind of network communications done by your computer"
    

Not very helpful.

[1] <http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html>

[2]
[http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html...](http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html#theory)

~~~
xymostech
I came here to say just this. Anyone who wants to do real socket programming
should learn some of the low level reasons for how sockets work behind the
scenes. Plus, it's a great read! (I especially like his story about IPv6)

------
rflrob
Is there a reason to catch all those exceptions? If you're just sys.exit()ing
anyways, why sacrifice all the traceback info?

~~~
yk
You should always assume, that a best effort network fails. Therefore, you
should always handle the exceptions ( even in a trivial example).

------
djtriptych
Decent tutorial, though I find the official Python HOWTO to be a more thorough
and appropriate introduction to sockets for the complete newbie...

<http://docs.python.org/howto/sockets.html>

~~~
obituary_latte
As a python newbie, I couldn't disagree more.

I would have saved hours while working on (and possibly completed) the recent
Stripe CTF. Frankly, I started to dislike the python docs thoroughly. However,
I'm very much looking forward to the much-rumored new docs--I very much dig
the language.

As an example to my point, however, look at the two side-by-side as an
aspiring tinkerer with the desire to send data over a socket. To me, the
aforementioned tutorial is miles ahead of the python docs.

~~~
djtriptych
We may have an unreconcilable difference in philosophy here. I understand
there is value in jumping straight to code, but I find real value in a (good)
treatment of the model you're coding against before jumping in.

Both tutorials are good, but I think a Python programmer totally new to
network programming, which is the audience of the OP, is better served first
reading that HOWTO before following the code samples...

~~~
obituary_latte
Understood.

For me, I just _can't_ learn that way--that's surely where the discrepancy is.
I've never been able to, say, read one of those O'Reilly programming books all
the way through (though I have bought a couple with the best of intentions). I
just have to start playing around. It's probably not the right way, but its
served me well. I think this is why the python docs don't work for me--they
don't seem suited to that type of learning.

------
Myrmornis
I really highly recommend "Foundations of Python Network Programming" by
Brandon Rhodes and John Goerzen. It's just one of the best technical books
I've read, from the opening example onwards.
<http://www.apress.com/9781430230038>

------
njharman
Shouldn't the first step be install <http://www.zeromq.org/>? That is some
seriously amazing stuff right there. Makes network programming (something I've
avoided for years) almost trivial.

~~~
peterwwillis
The point is (or should be) to learn how socket programming works so you know
what's going on under all that abstraction and why. That's also why we catch
all those exceptions: so we understand why something failed, and how to deal
with it in the future. It's also really fun to write complex networking apps
from scratch =)

~~~
njharman
If that was the point we should all break out our chemistry sets to refine
elements so we can create our logic chips and build up from there.

At some point you have to admit you've climbed down enough turtles and it's
time to get some shit done. I'm claiming ZeroMQ is far enough down. It's not
that much abstraction. It's mostly avoiding you the annoyances and giving you
framework of best practices.

~~~
aaronblohowiak
Each hacker choses how far down the rabbit hole they go, don't disparage
others for going deeper.

