[newbie] trying socket as a replacement for nc
drsalists at gmail.com
Sun Dec 15 02:03:14 CET 2013
On Sat, Dec 14, 2013 at 5:33 AM, Jean Dubois <jeandubois314 at 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 ?
>> t = Telnet(host, port)
>> print t.read_until('Whateverprompt')
>> # you can use read_very_eager also
> 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,
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.
More information about the Python-list