Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!bloom-beacon.mit.edu!panix!not-for-mail From: Grant Edwards Newsgroups: comp.lang.python Subject: Re: [newbie] trying socket as a replacement for nc Date: Thu, 12 Dec 2013 14:16:46 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 40 Message-ID: References: NNTP-Posting-Host: dsl.comtrol.com X-Trace: reader1.panix.com 1386857806 16041 64.122.56.22 (12 Dec 2013 14:16:46 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Thu, 12 Dec 2013 14:16:46 +0000 (UTC) User-Agent: slrn/1.0.1 (Linux) Xref: csiph.com comp.lang.python:61715 On 2013-12-11, Dan Stromberg wrote: > 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. Just to be pedantic: _TCP_ sockets reserver that right. UDP sockets do not, and do in fact guarantee that each message is discrete. [It appears that the OP is undoubtedly using TCP sockets.] > 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. And it _will_ fail someday in some odd circumstance when, for example, some customer is be using it via a dial-up PPP connection, or there is a satellite link in the path, or there's a flakey router somewhere, or... -- Grant Edwards grant.b.edwards Yow! Those people look at exactly like Donnie and gmail.com Marie Osmond!!