Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:: [': 0.04; 'aggregate': 0.07; 'paths': 0.07; 'reason,': 0.07; 'string': 0.09; 'assuming': 0.09; 'back.': 0.09; 'sake': 0.09; 'subject:trying': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'wrote': 0.14; 'adapter': 0.16; 'cc:name:python list': 0.16; 'discovery,': 0.16; 'measurement': 0.16; 'reliability.': 0.16; 'simple.': 0.16; 'sockets': 0.16; 'tcp': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'module': 0.19; 'split': 0.19; 'examples': 0.20; 'subject:] ': 0.20; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; '(see': 0.26; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; "doesn't": 0.30; 'dec': 0.30; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'page.': 0.31; 'jean': 0.31; 'allows': 0.31; 'probably': 0.32; 'linux': 0.33; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'done': 0.36; 'url:org': 0.36; 'performance': 0.37; 'skip:& 10': 0.38; 'e.g.': 0.38; 'pm,': 0.38; 'rather': 0.38; 'bad': 0.39; 'system.': 0.39; 'equipment': 0.61; "you're": 0.61; 'happen': 0.63; 'to:addr:gmail.com': 0.65; 'sample': 0.67; 'fact,': 0.69; 'heavy': 0.81; 'confusing': 0.84; 'seldom': 0.84; 'abstracts': 0.91; 'instrument': 0.93; '2013': 0.98 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=nC8Klf1FtoDoz4ANG0Ejj9nVMbPixJGLCOiUvvsRlIc=; b=PpTkncZuZdl6dDAvk7nkaqHQnq7/l6fgtYD11ufRrteovc0zz6GoIiVRVET/kXmxnZ W8lZgY4996MSZAOJElINJigayv/c//JsGC42YtxNeT1jNBtRJi7DcsXKRb+8uLqWBTwa qFkGtgoAhfggqBcbOvMO12v6zQkcxiKoLP9hlR2IaCYclzWBT2kN1fowHv1NcLdyHFwp /CDucq3CMcWvoHGWAhNgy0Xuo/VMnUTgCSLw/W0fl8PZeUrv6MsdPMrflLtY3dPh/6YY jfzaDIPxWygmCv2mkH1XTtcEoqeXqJErEjCRopaK0JIGvDhjnFDnSCSExP7G8pErqwDM 5Xzw== MIME-Version: 1.0 X-Received: by 10.180.211.212 with SMTP id ne20mr26475917wic.31.1386804036599; Wed, 11 Dec 2013 15:20:36 -0800 (PST) In-Reply-To: References: Date: Wed, 11 Dec 2013 15:20:36 -0800 Subject: Re: [newbie] trying socket as a replacement for nc From: Dan Stromberg To: Jean Dubois Content-Type: multipart/alternative; boundary=001a11c38a88f9867e04ed4a79ec Cc: Python List 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: 74 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1386804043 news.xs4all.nl 2896 [2001:888:2000:d::a6]:42128 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:61626 --001a11c38a88f9867e04ed4a79ec Content-Type: text/plain; charset=ISO-8859-1 On Wed, Dec 11, 2013 at 3:08 PM, Jean Dubois wrote: > I have an ethernet-rs232 adapter which allows me to connect to a > measurement instrument by means of netcat on a linux system. > e.g. entering nc 10.128.59.63 7000 > allows me to enter e.g. > *IDN? > after which I get an identification string of the measurement instrument > back. > I thought I could accomplish the same using the python module "socket" > and tried out the sample program below which doesn't work however: > Sockets reserve the right to split one socket.send() into multiple socket.recv()'s on the other end of the communication, or to aggregate multiple socket.send()'s into a single socket.recv() - pretty much any way the relevant IP stacks and communications equipment feel like for the sake of performance or reliability. The confusing thing about this is, it won't be done on every transmission - in fact, it'll probably happen rather seldom unless you're on a heavy loaded network or have some MTU issues (see Path MTU Discovery, and bear in mind that paths can change during a TCP session). But writing your code assuming it will never happen is a bad idea. For this reason, I wrote http://stromberg.dnsalias.org/~strombrg/bufsock.html , which abstracts away these complications, and actually makes things pretty simple. There are examples on the web page. HTH --001a11c38a88f9867e04ed4a79ec Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

= On Wed, Dec 11, 2013 at 3:08 PM, Jean Dubois <jeandubois314@gmail.c= om> wrote:
I have an ethernet-rs232 = adapter which allows me to connect to a measurement instrument by means of = netcat on a linux system.
e.g. entering nc 10.128.59.63 7000
allows me to enter e.g.
*IDN?
after which I get an identification string of the measurement instrument ba= ck.
I thought I could accomplish the same using the python module "socket&= quot;
and tried out the sample program below which doesn't work however:
Sockets reserve the right to split one socket.send() into multi= ple socket.recv()'s on the other end of the communication, or to aggreg= ate multiple socket.send()'s into a single socket.recv() - pretty much = any way the relevant IP stacks and communications equipment feel like for t= he sake of performance or reliability.

The confusing thing about this is, it won't be done on every transm= ission - in fact, it'll probably happen rather seldom unless you're= on a heavy loaded network or have some MTU issues (see Path MTU Discovery,= and bear in mind that paths can change during a TCP session).=A0 But writi= ng your code assuming it will never happen is a bad idea.

For this reason, I wrote http://stromberg.dnsalias.org/~strombrg/bufso= ck.html , which abstracts away these complications, and actually makes = things pretty simple.=A0 There are examples on the web page.

HTH

--001a11c38a88f9867e04ed4a79ec--