Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!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.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; '(so': 0.07; 'developer.': 0.07; 'agree,': 0.09; 'boundaries.': 0.09; 'newline': 0.09; 'prefix': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'jan': 0.12; 'delimit': 0.16; 'delimiters': 0.16; 'easier.': 0.16; 'fork': 0.16; 'newlines': 0.16; 'personally,': 0.16; 'send()': 0.16; 'tcp': 0.16; 'tends': 0.16; 'termination.': 0.16; 'unicode.': 0.16; 'ways:': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'cc:addr:python.org': 0.22; 'bytes': 0.24; 'module,': 0.24; 'unicode': 0.24; 'cc:2**0': 0.24; 'solutions.': 0.26; 'switch': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'chris': 0.29; 'leave': 0.29; 'strongly': 0.30; 'message- id:@mail.gmail.com': 0.30; '(which': 0.31; 'gives': 0.31; 'easier': 0.31; 'agreed.': 0.31; 'becoming': 0.31; 'convenience': 0.31; 'terminate': 0.31; 'critical': 0.32; 'figure': 0.32; 'another': 0.32; 'quite': 0.32; "i'd": 0.34; "can't": 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; "i'll": 0.36; 'url:org': 0.36; 'two': 0.37; 'being': 0.38; 'problems': 0.38; 'depends': 0.38; 'pm,': 0.38; 'rather': 0.38; 'little': 0.38; 'aside': 0.39; 'extremely': 0.39; 'either': 0.39; 'how': 0.40; 'even': 0.60; 'simple,': 0.60; 'most': 0.60; 'length': 0.61; 'full': 0.61; "you're": 0.61; 'first': 0.61; "you'll": 0.62; 'happen': 0.63; 'more': 0.64; 'to:addr:gmail.com': 0.65; 'world': 0.66; 'side': 0.67; 'internet': 0.71; '3.4': 0.84; 'asynchronous': 0.84; 'complex,': 0.84; 'end.': 0.84; 'traffic.': 0.84 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:to :cc:content-type; bh=Fue7XPMp/aMYjX89pse5rM6c5Q4tD9PxPzI4hLqcuV8=; b=KPEeffEpFrymd9QxkoFeTV67Xk1eDPli2VRN49ftjfaEcXldyX9bGQ+UX2YgZDhzoN kdMtMkOZySsQqHg939yzMQVU7zXbSAxoIXcbh5QZYkvNKq7n7o8D2F2OL/BHA0C37fBI JA/oTolPU0nXuW/4KWJX9+D/8MFqtmRvKzKpoFzewo81G1hmY74dc7nfUQQEy9/GYR7q y1gXXEl7YCLQBaUYHmZGNYNmg0iUfoGvH2xMTwoaw7V9K/iIdGMIqUIfMdb490ygdA/P NJzAGVxDzxeaS2WP65F82S4U5UAxPcR6dzx5tMRb/9jFRWl5VQnvAIrSIBeLnjSugjzn Aj/A== MIME-Version: 1.0 X-Received: by 10.194.248.233 with SMTP id yp9mr14299wjc.52.1389225188886; Wed, 08 Jan 2014 15:53:08 -0800 (PST) In-Reply-To: References: <22d58d76-f2c2-4a1d-8049-3409ac4665d3@googlegroups.com> Date: Wed, 8 Jan 2014 15:53:08 -0800 Subject: Re: Learning python networking From: Dan Stromberg To: Chris Angelico Content-Type: text/plain; charset=ISO-8859-1 Cc: "python-list@python.org" 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: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389225196 news.xs4all.nl 2918 [2001:888:2000:d::a6]:49032 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63540 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 > do one thing at a time on localhost, but it won't be reliable on the > internet or when there's more traffic. So you'll need to delimit > messages; I recommend you use one of two classic ways: either prefix > it with a length (so you know how many more bytes to receive), or > terminate it with a newline (which depends on there not being a > newline in the text). Completely agree, and I'll point out http://stromberg.dnsalias.org/~dstromberg/bufsock.html , which makes it a little easier to deal with delimiters like newlines or null termination. > Another rather important point, in two halves. You're writing this for > Python 2, and you're writing with no Unicode handling. I strongly > recommend that you switch to Python 3 and support full Unicode. Agreed. It's time modernize. Don't leave out people on the other side of the world for no reason other than a modicum of convenience for the developer. > 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 asynchronous I/O, EG twisted. It tends to give very complex, uniprocessor solutions to problems, even when those problems have quite simple, alternative solutions. I'd rather just accept and fork in most cases, with or without multiprocessing.