Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #62094

Re: [newbie] trying socket as a replacement for nc

Path csiph.com!usenet.pasdenom.info!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <prvs=0559fdd6f=jeanmichel@sequans.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'scripts': 0.03; 'subject:: [': 0.04; 'broken': 0.04; 'syntax': 0.04; 'interpreter.': 0.07; 'nasty': 0.07; 'subject:trying': 0.09; 'variant': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; 'def': 0.12; 'caring': 0.16; 'expert.': 0.16; 'first:': 0.16; 'folks,': 0.16; 'fully,': 0.16; 'port)': 0.16; 'success:': 0.16; 'syntax,': 0.16; 'syntaxerror:': 0.16; 'language': 0.16; 'wrote:': 0.18; 'implementing': 0.19; 'subject:] ': 0.20; 'written': 0.21; 'import': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'point': 0.28; 'host': 0.29; 'am,': 0.29; 'dec': 0.30; 'vendor': 0.30; "skip:' 10": 0.31; 'jean': 0.31; 'file': 0.32; '-----': 0.33; 'basic': 0.35; 'something': 0.35; 'test': 0.35; 'but': 0.35; 'sequence': 0.36; 'done': 0.36; 'should': 0.36; 'level': 0.37; 'feedback': 0.38; 'remote': 0.38; 'server': 0.38; 'thank': 0.38; 'rather': 0.38; 'even': 0.60; 'equipment': 0.61; 'success': 0.61; 'simple': 0.61; 'you.': 0.62; 'information': 0.63; 'received:194': 0.64; 'great': 0.65; 'to:addr:gmail.com': 0.65; 'details': 0.65; 'notice:': 0.67; 'invalid': 0.68; 'person,': 0.68; 'privileged.': 0.69; 'wish': 0.70; 'disclose': 0.74; 'low': 0.83; 'medium.': 0.91; '2013': 0.98
X-IronPort-AV E=Sophos;i="4.95,496,1384297200"; d="scan'208";a="2247294"
X-Virus-Scanned amavisd-new at zimbra.sequans.com
Date Mon, 16 Dec 2013 20:21:15 +0100 (CET)
From Jean-Michel Pichavant <jeanmichel@sequans.com>
To Chris Angelico <rosuav@gmail.com>
In-Reply-To <CAPTjJmpH5NhhFpmzbpmAk-VV4r2zkiPBi6mKyDrM4fMd7T8eOA@mail.gmail.com>
Subject Re: [newbie] trying socket as a replacement for nc
MIME-Version 1.0
X-Mailer Zimbra 7.2.4_GA_2900 (ZimbraWebClient - GC31 (Win)/7.2.4_GA_2900)
Content-Type text/plain; charset="utf-8"
Content-Transfer-Encoding base64
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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4232.1387221677.18130.python-list@python.org> (permalink)
Lines 38
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1387221677 news.xs4all.nl 2952 [2001:888:2000:d::a6]:57623
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:62094

Show key headers only | View raw



----- Original Message -----
> On Tue, Dec 17, 2013 at 5:26 AM, Jean Dubois
> <jeandubois314@gmail.com> wrote:
> >> Try something simple first:
> >> import telnetlib
> >> host = '10.128.59.63'
> >> port = 7000
> >> t = Telnet(host, port)
> >> def flush()
> >>   t.read_very_eager()
> >> def sendCmd(cmd)
> >>   t.write('%s\n' % cmd)
> >>   return flush()
> >> flush()
> >> print sendCmd('*IDN?')
> >> print sendCmd('*OPC?')
> > Still no success:
> > jean@mantec:~$ ./test.py
> >   File "./test.py", line 7
> >     def flush()
> >               ^
> > SyntaxError: invalid syntax
> >
> >
> > Tried it both with python2 and python3, same error...
> 
> Folks, the OP isn't an expert. Please test your scripts before
> posting!
> 
> I don't have everything I need to test this fully, but here's a
> variant of the above that's at least syntactically correct:
> 
> from telnetlib import *
> host = '10.128.59.63'
> port = 7000
> t = Telnet(host, port)
> def flush():
>   t.read_very_eager()
> def sendCmd(cmd):
>   t.write('%s\n' % cmd)
>   return flush()
> flush()
> print sendCmd('*IDN?')
> print sendCmd('*OPC?')
> 
> It's written for Python 2, so use that interpreter.
> 
> ChrisA

It was done on purpose, for educational purpose... :) 
My bad, however I should point that learning the very basic of a language by implementing a low level equipment remote protocol is rather ambitious.
By experience I know that you are annoyed by a crapload of nasty details without even caring about the python syntax, including:
  * LF/CR sequence
  * Inconsistent  answer pattern, depending on the equipment vendor
  * broken netcode that can block the remote server
  * timeouts
  * poor equipment feedback
I still wish Jean a great success :)


JM  


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: [newbie] trying socket as a replacement for nc Jean-Michel Pichavant <jeanmichel@sequans.com> - 2013-12-16 20:21 +0100
  Re: [newbie] trying socket as a replacement for nc Jean Dubois <jeandubois314@gmail.com> - 2013-12-16 13:01 -0800

csiph-web