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


Groups > comp.lang.python > #61825 > unrolled thread

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

Started byJean-Michel Pichavant <jeanmichel@sequans.com>
First post2013-12-13 16:35 +0100
Last post2013-12-15 13:14 -0800
Articles 6 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  Re: [newbie] trying socket as a replacement for nc Jean-Michel Pichavant <jeanmichel@sequans.com> - 2013-12-13 16:35 +0100
    Re: [newbie] trying socket as a replacement for nc Jean Dubois <jeandubois314@gmail.com> - 2013-12-14 05:33 -0800
      Re: [newbie] trying socket as a replacement for nc Dan Stromberg <drsalists@gmail.com> - 2013-12-14 17:03 -0800
        Re: [newbie] trying socket as a replacement for nc Jean Dubois <jeandubois314@gmail.com> - 2013-12-15 07:35 -0800
          Re: [newbie] trying socket as a replacement for nc Chris Angelico <rosuav@gmail.com> - 2013-12-16 02:50 +1100
          Re: [newbie] trying socket as a replacement for nc Dan Stromberg <drsalists@gmail.com> - 2013-12-15 13:14 -0800

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

FromJean-Michel Pichavant <jeanmichel@sequans.com>
Date2013-12-13 16:35 +0100
SubjectRe: [newbie] trying socket as a replacement for nc
Message-ID<mailman.4072.1386948939.18130.python-list@python.org>
----- Original Message -----
> 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:
> #!/usr/bin/env python
> 
> """
> A simple echo client
> """
> import socket
> host = '10.128.59.63'
> port = 7000
> size = 10
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> s.connect((host,port))
> s.send('*IDN?')
> data = s.recv(size)
> s.close()
> print 'Received:', data
> 
> Can anyone here tell me how to do it properly?
> thanks in advance
> jean

Such equipment often implements a telnet protocol. Have use try using the telnetlib module ?
http://docs.python.org/2/library/telnetlib.html

t = Telnet(host, port)
t.write('*IDN?')
print t.read_until('Whateverprompt')
# you can use read_very_eager also

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.

[toc] | [next] | [standalone]


#61896

FromJean Dubois <jeandubois314@gmail.com>
Date2013-12-14 05:33 -0800
Message-ID<180e238a-2110-41d9-a13f-df3355bd26c4@googlegroups.com>
In reply to#61825
Op vrijdag 13 december 2013 16:35:31 UTC+1 schreef Jean-Michel Pichavant:
> ----- Original Message -----
> > 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:
> > #!/usr/bin/env python
> > 
> > """
> > A simple echo client
> > """
> > import socket
> > host = '10.128.59.63'
> > port = 7000
> > size = 10
> > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> > s.connect((host,port))
> > s.send('*IDN?')
> > data = s.recv(size)
> > s.close()
> > print 'Received:', data
> > 
> > Can anyone here tell me how to do it properly?
> > thanks in advance
> > jean
> Such equipment often implements a telnet protocol. Have use try using the telnetlib module ?
> http://docs.python.org/2/library/telnetlib.html
> t = Telnet(host, port)
> t.write('*IDN?')
> print t.read_until('Whateverprompt')
> # you can use read_very_eager also
> JM
Thanks for the suggestion, I'll first wait for a response from Dan Stromberg concerning how to install his module, if he doesn't answer or if I'm still unsuccessfull then I'll try out your suggestion

kind regards,
jean

[toc] | [prev] | [next] | [standalone]


#61924

FromDan Stromberg <drsalists@gmail.com>
Date2013-12-14 17:03 -0800
Message-ID<mailman.4130.1387069401.18130.python-list@python.org>
In reply to#61896
On Sat, Dec 14, 2013 at 5:33 AM, Jean Dubois <jeandubois314@gmail.com> wrote:
> Op vrijdag 13 december 2013 16:35:31 UTC+1 schreef Jean-Michel Pichavant:
>> ----- Original Message -----
>> > 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:
>> > #!/usr/bin/env python
>> >
>> > """
>> > A simple echo client
>> > """
>> > import socket
>> > host = '10.128.59.63'
>> > port = 7000
>> > size = 10
>> > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>> > s.connect((host,port))
>> > s.send('*IDN?')
>> > data = s.recv(size)
>> > s.close()
>> > print 'Received:', data
>> >
>> > Can anyone here tell me how to do it properly?
>> > thanks in advance
>> > jean
>> Such equipment often implements a telnet protocol. Have use try using the telnetlib module ?
>> http://docs.python.org/2/library/telnetlib.html
>> t = Telnet(host, port)
>> t.write('*IDN?')
>> print t.read_until('Whateverprompt')
>> # you can use read_very_eager also
>> JM
> Thanks for the suggestion, I'll first wait for a response from Dan Stromberg concerning how to install his module, if he doesn't answer or if I'm still unsuccessfull then I'll try out your suggestion
>
> kind regards,
> jean
> --
> https://mail.python.org/mailman/listinfo/python-list

You can "svn checkout <url>".  You might try Sliksvn if you're on
Windows, or if you're on Linux it's in synaptic or yum or whatever.

You can "wget <url>".

You can bring up the URL in a web browser and cut and paste.

[toc] | [prev] | [next] | [standalone]


#61949

FromJean Dubois <jeandubois314@gmail.com>
Date2013-12-15 07:35 -0800
Message-ID<a95c6412-c2d2-41fc-a963-bdd87b2b0987@googlegroups.com>
In reply to#61924
Op zondag 15 december 2013 02:03:14 UTC+1 schreef Dan Stromberg:
> On Sat, Dec 14, 2013 at 5:33 AM, Jean Dubois <jeandubois314@gmail.com> wrote:
> > Op vrijdag 13 december 2013 16:35:31 UTC+1 schreef Jean-Michel Pichavant:
> >> ----- Original Message -----
> >> > 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:
> >> > #!/usr/bin/env python
> >> >
> >> > """
> >> > A simple echo client
> >> > """
> >> > import socket
> >> > host = '10.128.59.63'
> >> > port = 7000
> >> > size = 10
> >> > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> >> > s.connect((host,port))
> >> > s.send('*IDN?')
> >> > data = s.recv(size)
> >> > s.close()
> >> > print 'Received:', data
> >> >
> >> > Can anyone here tell me how to do it properly?
> >> > thanks in advance
> >> > jean
> >> Such equipment often implements a telnet protocol. Have use try using the telnetlib module ?
> >> http://docs.python.org/2/library/telnetlib.html
> >> t = Telnet(host, port)
> >> t.write('*IDN?')
> >> print t.read_until('Whateverprompt')
> >> # you can use read_very_eager also
> >> JM
> > Thanks for the suggestion, I'll first wait for a response from Dan Stromberg concerning how to install his module, if he doesn't answer or if I'm still unsuccessfull then I'll try out your suggestion
> >
> > kind regards,
> > jean
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> You can "svn checkout <url>".  You might try Sliksvn if you're on
> Windows, or if you're on Linux it's in synaptic or yum or whatever.
> You can "wget <url>".
> You can bring up the URL in a web browser and cut and paste.
I'm using Linux, I did the following:
svn checkout http://stromberg.dnsalias.org/svn/bufsock/
which resulted in a directory 'bufsock' being added to my home-directory, 
Do I have to run further commands on the files in this directory?
How do I make Python aware of the existence of this new module?

thanks in advance
jean 

[toc] | [prev] | [next] | [standalone]


#61950

FromChris Angelico <rosuav@gmail.com>
Date2013-12-16 02:50 +1100
Message-ID<mailman.4142.1387122652.18130.python-list@python.org>
In reply to#61949
On Mon, Dec 16, 2013 at 2:35 AM, Jean Dubois <jeandubois314@gmail.com> wrote:
> I'm using Linux, I did the following:
> svn checkout http://stromberg.dnsalias.org/svn/bufsock/
> which resulted in a directory 'bufsock' being added to my home-directory,
> Do I have to run further commands on the files in this directory?
> How do I make Python aware of the existence of this new module?

Have a look in that directory. It seems to simply have a bufsock.py
which is the module to import.

That said, though, you may have to deal with dependencies. The source
code of bufsock.py references a python2x3 module (which Google tells
me is by the same author), so you may need to grab that, too.

ChrisA

[toc] | [prev] | [next] | [standalone]


#61964

FromDan Stromberg <drsalists@gmail.com>
Date2013-12-15 13:14 -0800
Message-ID<mailman.4151.1387142054.18130.python-list@python.org>
In reply to#61949
On Sun, Dec 15, 2013 at 7:35 AM, Jean Dubois <jeandubois314@gmail.com> wrote:

>> You can "svn checkout <url>".  You might try Sliksvn if you're on
>> Windows, or if you're on Linux it's in synaptic or yum or whatever.
>> You can "wget <url>".
>> You can bring up the URL in a web browser and cut and paste.
> I'm using Linux, I did the following:
> svn checkout http://stromberg.dnsalias.org/svn/bufsock/
> which resulted in a directory 'bufsock' being added to my home-directory,
> Do I have to run further commands on the files in this directory?
> How do I make Python aware of the existence of this new module?

You can put the files (bufsock.py and python2x3.py) in your current
working directory - Python will import from your CWD.  I believe
python2x3.py should be checked out via an external reference since you
used svn.

You can put the files in your site-packages directory.

You can put the files in a directory like ~/lib, and then
sys.path.insert(0, os.path.expanduser('~/lib')) .

I probably should make it pip'able, but I don't think it's going to
happen today.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web