Re: Learning python networking

2014-01-15 Thread William Ray Wing
On Jan 15, 2014, at 7:52 AM, Chris Angelico wrote: [megabyte] > One of the fundamentals of the internet is that connections *will* > break. A friend of mine introduced me to Magic: The Gathering via a > program that couldn't handle drop-outs, and it got extremely > frustrating - we couldn't get

Re: Learning python networking

2014-01-15 Thread Chris Angelico
On Thu, Jan 16, 2014 at 3:43 AM, William Ray Wing wrote: > I was assuming another user picking up the connection using sniffed > credentials (and yes, despite all the work on ssh, not all man-in-the-middle > attacks have been killed). If that can happen, then I would much prefer that it kick my

Re: Learning python networking

2014-01-15 Thread William Ray Wing
On Jan 15, 2014, at 11:31 AM, Chris Angelico wrote: > On Thu, Jan 16, 2014 at 3:25 AM, William Ray Wing wrote: >> On Jan 15, 2014, at 7:52 AM, Chris Angelico wrote: >>> One of the fundamentals of the internet is that connections *will* >>> break. A friend of mine introduced me to Magic: The Gat

Re: Learning python networking

2014-01-15 Thread Chris Angelico
On Thu, Jan 16, 2014 at 3:31 AM, Chris Angelico wrote: > I'm assuming an authentication system > that stipulates one single active connection per authenticated user Incidentally, in an environment where everything's trusted (LAN or localhost), the "authentication system" can be as simple as "type

Re: Learning python networking

2014-01-15 Thread Chris Angelico
On Thu, Jan 16, 2014 at 3:25 AM, William Ray Wing wrote: > On Jan 15, 2014, at 7:52 AM, Chris Angelico wrote: >> One of the fundamentals of the internet is that connections *will* >> break. A friend of mine introduced me to Magic: The Gathering via a >> program that couldn't handle drop-outs, and

Re: Learning python networking

2014-01-15 Thread Chris Angelico
On Wed, Jan 15, 2014 at 11:52 PM, Chris Angelico wrote: > One of the fundamentals of the internet is that connections *will* > break. A friend of mine introduced me to Magic: The Gathering via a > program that couldn't handle drop-outs, and it got extremely > frustrating - we couldn't get a game g

Re: Learning python networking

2014-01-15 Thread Chris Angelico
On Thu, Jan 16, 2014 at 12:31 AM, Frank Millman wrote: > I think you may have omitted a line there - > > def gets(): > while '\n' not in buffer: > data = sock.recv(1024) > if not data: > # Client is disconnected, handle it gracefully > return None # or s

Re: Learning python networking

2014-01-15 Thread Frank Millman
"Chris Angelico" wrote in message news:CAPTjJmpb6yr-VpWypbJQn0a=pnjvnv2cchvbzak+v_5josq...@mail.gmail.com... > You just run a loop like this: > > buffer = b'' > > def gets(): >while '\n' not in buffer: >data = sock.recv(1024) >if not data: ># Client is disconnecte

Re: Learning python networking

2014-01-15 Thread Chris Angelico
On Wed, Jan 15, 2014 at 9:37 PM, Paul Pittlerson wrote: > I'm sorry if this is a bit late of a response, but here goes. > > Big thanks to Chris Angelico for his comprehensive reply, and yes, I do have > some questions! Best way to learn! And the thread's not even a week old, this isn't late. Som

Re: Learning python networking

2014-01-15 Thread Denis McMahon
On Wed, 15 Jan 2014 02:37:05 -0800, Paul Pittlerson wrote: >> One extremely critical point about your protocol. TCP is a stream - you >> don't have message boundaries. You can't depend on one send() becoming >> one recv() at the other end. It might happen to work when you do one >> thing at a time

Re: Learning python networking

2014-01-15 Thread Paul Pittlerson
I'm sorry if this is a bit late of a response, but here goes. Big thanks to Chris Angelico for his comprehensive reply, and yes, I do have some questions! > On Thursday, January 9, 2014 1:29:03 AM UTC+2, Chris Angelico wrote: > Those sorts of frameworks would be helpful if you need to scale to

Re: Learning python networking

2014-01-09 Thread Alister
On Wed, 08 Jan 2014 19:49:40 -0800, Dan Stromberg wrote: > > The third quote, from Brian Kernighan, seems to underestimate the > complexity of asynchronous programming in the large - it's probably not > just twice as hard. Perhaps it should be rephrased as "at least twice as hard" It really doe

Re: Learning python networking

2014-01-08 Thread Chris Angelico
On Thu, Jan 9, 2014 at 2:49 PM, Dan Stromberg wrote: > The third quote, from Brian Kernighan, seems to underestimate the > complexity of asynchronous programming in the large - it's probably > not just twice as hard. Yeah, which is why I recommended a threaded approach to the OP. It won't scale t

Re: Learning python networking

2014-01-08 Thread Dan Stromberg
On Wed, Jan 8, 2014 at 4:07 PM, Chris Angelico wrote: > Maybe it's not the best way to do things, but it can be extremely > simple in the code. For small projects, the added complexity doesn't bite you. At least, not much. For large projects, with thousands or millions of callbacks, it can be v

Re: Learning python networking

2014-01-08 Thread Chris Angelico
On Thu, Jan 9, 2014 at 10:53 AM, Dan Stromberg wrote: >> Using Python 3.4 (which isn't yet >> stable, but you can download betas) also gives you an asyncio module, >> but I'd leave that aside for the moment; first figure out threading, >> it's likely to be easier. > > Personally, I don't like asyn

Re: Learning python networking

2014-01-08 Thread Dan Stromberg
Nice response Chris. Seriously. On Wed, Jan 8, 2014 at 3:29 PM, Chris Angelico wrote: > One extremely critical point about your protocol. TCP is a stream - > you don't have message boundaries. You can't depend on one send() > becoming one recv() at the other end. It might happen to work when you

Re: Learning python networking

2014-01-08 Thread Chris Angelico
On Thu, Jan 9, 2014 at 9:27 AM, Paul Pittlerson wrote: > I'm trying to learn about socket, how to create and handle connections in > python. Awesome! I *love* socket networking. (Really. It's awesome. I've written a couple of MUD servers and quite a few MUD clients.) > This is the best I could

Learning python networking

2014-01-08 Thread Paul Pittlerson
I'm trying to learn about socket, how to create and handle connections in python. This is the best I could come up with on my own, please take a look and give me critique: Server script: http://pastebin.com/KtapYfM0 Client script: http://pastebin.com/t4dYygmX How to run it: I open 3 terminals,