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

2013-12-18 Thread Jean Dubois
Op dinsdag 17 december 2013 10:37:37 UTC+1 schreef Jean-Michel Pichavant:
  I'm a newbie in Python programming that is very much true, and
  contrary to what you seem to suggest I did my homework
 At no point that was my intention, my apologies.
OK, no problem
 If you fixed the syntax error, you should be pretty close to the solution 
 though.
thanks, I'll look further into it when I find a bit more time

kind regards,
jean
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-18 Thread Jean Dubois
Op woensdag 18 december 2013 14:04:08 UTC+1 schreef Jean Dubois:
 Op dinsdag 17 december 2013 10:37:37 UTC+1 schreef Jean-Michel Pichavant:
   I'm a newbie in Python programming that is very much true, and
   contrary to what you seem to suggest I did my homework
  At no point that was my intention, my apologies.
 OK, no problem
  If you fixed the syntax error, you should be pretty close to the solution 
  though.
 thanks, I'll look further into it when I find a bit more time
I finally got it working:
#!/usr/bin/env python
import telnetlib
host = '10.128.56.202'
port = 6000
t = telnetlib.Telnet(host, port)
t.read_very_eager() #flush
t.write('\n')
prompt = t.read_very_eager()
t.write('*IDN?\n')
print t.read_until('\n',5)

thanks to all here for the help offered

kind regards,
jean

-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-18 Thread Jean Dubois
Op woensdag 18 december 2013 15:48:43 UTC+1 schreef Jean Dubois:
 Op woensdag 18 december 2013 14:04:08 UTC+1 schreef Jean Dubois:
  Op dinsdag 17 december 2013 10:37:37 UTC+1 schreef Jean-Michel Pichavant:
I'm a newbie in Python programming that is very much true, and
contrary to what you seem to suggest I did my homework
   At no point that was my intention, my apologies.
  OK, no problem
   If you fixed the syntax error, you should be pretty close to the solution 
   though.
  thanks, I'll look further into it when I find a bit more time
 I finally got it working:
 #!/usr/bin/env python
 import telnetlib
 host = '10.128.56.202'
 port = 6000
 t = telnetlib.Telnet(host, port)
 t.read_very_eager() #flush
 t.write('\n')
 prompt = t.read_very_eager()
 t.write('*IDN?\n')
 print t.read_until('\n',5)

I erased the two superfluous lines in the code above, so the code now is this:
#!/usr/bin/env python
import telnetlib
host = '10.128.56.202'
port = 6000
t = telnetlib.Telnet(host, port)
t.read_very_eager() #flush
t.write('*IDN?\n')
readstring=t.read_until('\n',5)

jean
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-18 Thread 88888 Dihedral

  8 Dihedral dihedral88...@gmail.com wrote:
 
 
 
  It is trivial to use UDP with 
 
  forward error correction such as 
 
  the CD in 1982.
 
 
 
 CD uses Reed-Solomon coding, which is great for correcting the types of 
 
 errors expected on a CD.  Namely, bursts of bit errors caused by 
 
 localized failure of the optical coating, scratches, dirt, etc.  It 
 

Don't you interleave your bytes of data
first before forming several UDP 
packets to send to the receiver?

If a whole packet is lost or 
timed out, then just mark missed bytes
in the missed UDP as erasures.

 wouldn't be hard to build something like that on top of UDP, but those 
 
 sorts of errors are not what you typically see in networks.
 
 
 
 It's relatively rare for a bit to get corrupted in a network packet.  
 
 And, when it does, it's almost certainly caught by lower-level 
 
 mechanisms such as ethernet frame CRC.  Much more likely is for a packet 
 
 to get dropped because of queue overflow, or for sequential packets to 
 
 arrive out of order due to multiple transmission paths with different 
 
 latencies.  Those are the sorts of things TCP protects against.
 
 
 
 Sure, you could implement retransmit timers and packet reordering in 
 
 user code, but it would be distinctly non-trivial and ultimately you 
 
 would end up reinventing most of TCP.  Except that your implementation 
 
 would suck compared to the kernel algorithms which have been 
 
 continuously tested and fine-tuned for the past 30 years.

-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-17 Thread Jean-Michel Pichavant
 I'm a newbie in Python programming that is very much true, and
 contrary to what you seem to suggest I did my homework

At no point that was my intention, my apologies.
If you fixed the syntax error, you should be pretty close to the solution 
though.

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.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-16 Thread Jean Dubois
Op donderdag 12 december 2013 22:23:22 UTC+1 schreef Dan Stromberg:
 On Thu, Dec 12, 2013 at 12:28 AM, Jean Dubois jeandubois...@gmail.com wrote:
  On Thursday, December 12, 2013 12:20:36 AM UTC+1, Dan Stromberg wrote:
  On Wed, Dec 11, 2013 at 3:08 PM, Jean Dubois jeandu...@gmail.com 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
 
  Dear Dan,
  Could you copy paste here the code for your function I have to add to my 
  program?
 This is untested, but it should be something like the following:
 #!/usr/bin/env python
 
 A simple echo client
 
 import socket as socket_mod
 import bufsock as bufsock_mod
 host = '10.128.59.63'
 port = 7000
 size = 10
 socket = socket_mod.socket(socket.AF_INET, socket.SOCK_STREAM)
 socket.connect((host,port))
 bufsock = bufsock_mod.bufsock(socket)
 bufsock.send('*IDN?')
 data = bufsock.recv(size)
 bufsock.close()
 print 'Received:', data
 You might look over
 http://stackoverflow.com/questions/19918307/retrieve-file-information-located-on-a-different-application-server-using-python/19918706#19918706
 for a more complete example.
So this is what I did:
1. svn checkout http://stromberg.dnsalias.org/svn/bufsock/
2. cd ~/bufsock/trunk
3. I made this test-file buftest.py with the following contents:
#!/usr/bin/env python


A simple echo client

import socket as socket_mod
import bufsock as bufsock_mod
host = '10.128.59.63'
port = 7000
size = 10
socket = socket_mod.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.connect((host,port))
bufsock = bufsock_mod.bufsock(socket)
bufsock.send('*IDN?')
data = bufsock.recv(size)
bufsock.close()
print 'Received:', data 

4. chmod +x buftest.py
5. ./buftest.py
6. This results in the following error message:
Traceback (most recent call last):
  File ./buftest.py, line 11, in module
socket = socket_mod.socket(socket.AF_INET, socket.SOCK_STREAM)
NameError: name 'socket' is not defined

Probably there is still something wrong, can anyone here help me further?

kind regards,
jean
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-16 Thread Ervin Hegedüs
hello,

 #!/usr/bin/env python
 
 
 A simple echo client
 
 import socket as socket_mod
 import bufsock as bufsock_mod
[...]
 Traceback (most recent call last):
   File ./buftest.py, line 11, in module
 socket = socket_mod.socket(socket.AF_INET, socket.SOCK_STREAM)
 NameError: name 'socket' is not defined

you should replace the socket.AF_INET to socket_mod.AF_INET, and
socket.SOCK_STREAM to socket_mod.SOCK_STREAM, if you've imported
socket modul as socket_mod. But this is just an idea... :)


a.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-16 Thread Jean-Michel Pichavant
  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
 
 
 Could you tell me how to install telnetlib on a linux-system (it's
 not
 available via apt-get install as I see it)
 
 kind regards,
 jean
 

Please keep it on list, some other may have the same install issue or someone 
could have better insights on installing telnetlib.

telnetlib is part of the standard modules in my Debian squeeze(python 2.5). 
Looking at the doc, it looks like it's available for python 3 as well. Strange 
that you don't have it.

Did you try

import telnetlib

?

Note that in the code above I forgot the EOF, which is very much dependent of 
the equipment itself.

You may have to write
t.write('*IDN?\n')
or
t.write('IDN?\n\r')

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.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-16 Thread Jean-Michel Pichavant
 Did you try
 
 import telnetlib
 
 ?
 
 Note that in the code above I forgot the EOF, which is very much
 dependent of the equipment itself.
 
 You may have to write
 t.write('*IDN?\n')
 or
 t.write('IDN?\n\r')
 
 JM


Additionally, here's the code we're using for our signal generators, just to 
give you a broad idea:

def getError(self):
error = self._extractRsp(self._sendCmd('SYST:ERR?', 10))
if 'No error' in error:
return None
else:
return error

def _sendCmd(self, aCmd, timeout):
self.send(str(aCmd) + self.SEND_LFCR)

waitPattern = [self.PROMPT]
try:
index, _, rsp= self._telnet.expect(waitPattern, timeout)
except  EOFError:
self._logger.error('Connection unexpectedly closed 
while sending/reading/ data.')
raise MxgError('Connection unexpectedly closed while 
sending the command %s' % aCmd)

if index == -1:
raise MxgError('Timeout occurred while sendind the 
command %s' % aCmd)

return rs


def _extractRsp(self, rawRsp):
# the returned string should be something like 
'\r\nresponse\r\nprompt'
# or '\r\nprompt'
# tries to extract the response only, removing the additional 
carriage returns and prompt
rawRsp = rawRsp.replace(self.READ_LFCR+self.PROMPT, '')
if rawRsp.startswith(self.READ_LFCR):
rawRsp = rawRsp[2:]
return rawRs


-- 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.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-16 Thread Jean Dubois
Op maandag 16 december 2013 11:29:12 UTC+1 schreef Jean-Michel Pichavant:
   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
  
  
  Could you tell me how to install telnetlib on a linux-system (it's
  not
  available via apt-get install as I see it)
  
  kind regards,
  jean
  
 Please keep it on list, some other may have the same install issue or someone 
 could have better insights on installing telnetlib.
 telnetlib is part of the standard modules in my Debian squeeze(python 2.5). 
 Looking at the doc, it looks like it's available for python 3 as well. 
 Strange that you don't have it.
 Did you try
 import telnetlib
 ?
 Note that in the code above I forgot the EOF, which is very much dependent of 
 the equipment itself.
 You may have to write
 t.write('*IDN?\n')
 or
 t.write('IDN?\n\r')
 JM
Here is the code:
#!/usr/bin/env python
import telnetlib
host = '10.128.59.63'
port = 7000
t = Telnet(host, port)
t.write('*IDN?\n')
print t.read_until('Whateverprompt')
# you can use read_very_eager also

and this is the result of executing the code(from which I deduce I have to
install telnetlib, but how?)
Traceback (most recent call last):
  File ./nctelnet.py, line 5, in module
t = Telnet(host, port)
NameError: name 'Telnet' is not defined

kind regards,
jean
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-16 Thread Jean-Michel Pichavant
 Here is the code:
 #!/usr/bin/env python
 import telnetlib
 host = '10.128.59.63'
 port = 7000
 t = Telnet(host, port)
 t.write('*IDN?\n')
 print t.read_until('Whateverprompt')
 # you can use read_very_eager also
 
 and this is the result of executing the code(from which I deduce I
 have to
 install telnetlib, but how?)
 Traceback (most recent call last):
   File ./nctelnet.py, line 5, in module
 t = Telnet(host, port)
 NameError: name 'Telnet' is not defined
 
 kind regards,
 jean

t = telnetlib.Telnet(host, port)

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.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-16 Thread 88888 Dihedral
On Friday, December 13, 2013 5:58:49 AM UTC+8, Chris Angelico wrote:
 On Fri, Dec 13, 2013 at 8:27 AM, Dan Stromberg drsali...@gmail.com wrote:
 
  On Thu, Dec 12, 2013 at 6:16 AM, Grant Edwards invalid@invalid.invalid 
  wrote:
 
 
 
  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.]
 
 
 
  I haven't done a lot of UDP, but are you pretty sure UDP can't at
 
  least fragment large packets?  What's a router or switch to do if the
 
  Path MTU isn't large enough for an original packet?
 
 
 
  http://www.gamedev.net/topic/343577-fragmented-udp-packets/
 
 
 
 I'm no expert on this (mostly I do TCP, or UDP with fairly small
 
 packets), but the packet should be reassembled at the far end. When
 
 your application comes to receive it, it'll receive the entire UDP
 
 packet as a whole.
 
 
 
 UDP fragmentation has several problems. First, if any fragment is
 
 lost, it won't be retransmitted (as TCP will), so the whole datagram
 
 is lost. And secondly, if you stream data across the network in a
 
 series of packets just a little too large to fit, each one will get
 
 split in two and you'll end up with twice as many packets going out,
 
 ergo abysmal performance. With TCP, there's the chance that the sender
 
 and receiver can between them figure out what packet size to use (cf
 
 path MTU discovery), but that won't happen with UDP unless the
 
 application consciously does it. So it's something to be cautious of
 
 in terms of performance, but if you want to send large UDP packets
 
 because they make sense, just go ahead and do it.
 
 
 
 Now, if you want reliability AND datagrams, it's a lot easier to add
 
 boundaries to a TCP stream (sentinel or length prefixes) than to add
 
 reliability to UDP...
 
 
 
 ChrisA
It is trivial to use UDP with 
forward error correction such as 
the CD in 1982.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-16 Thread Chris Angelico
On Mon, Dec 16, 2013 at 11:38 PM, 8 Dihedral
dihedral88...@gmail.com wrote:
 It is trivial to use UDP with
 forward error correction such as
 the CD in 1982.

This is another reason for moving to IPv6. With IPv4, the size of a
datagram is limited to 64KB, but with IPv6, you could carry an entire
CD's contents in a single message. You could not carry a DVD, though,
so Dihedral is quite correct to cite the CD here.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-16 Thread Jean Dubois
Op maandag 16 december 2013 13:05:41 UTC+1 schreef Jean-Michel Pichavant:
  Here is the code:
  #!/usr/bin/env python
  import telnetlib
  host = '10.128.59.63'
  port = 7000
  t = Telnet(host, port)
  t.write('*IDN?\n')
  print t.read_until('Whateverprompt')
  # you can use read_very_eager also
  
  and this is the result of executing the code(from which I deduce I
  have to
  install telnetlib, but how?)
  Traceback (most recent call last):
File ./nctelnet.py, line 5, in module
  t = Telnet(host, port)
  NameError: name 'Telnet' is not defined
  
  kind regards,
  jean
 t = telnetlib.Telnet(host, port)
this helps, but I don't know what to do with 
print t.read_until('Whateverprompt')

should I send CTRL-ALT-ALTGR-] after some time?

kind regards,
jean
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-16 Thread Roy Smith
On Friday, December 13, 2013 5:58:49 AM UTC+8, Chris Angelico wrote:
  Now, if you want reliability AND datagrams, it's a lot easier to add
  boundaries to a TCP stream (sentinel or length prefixes) than to add
  reliability to UDP...

In article 11cb8cd3-7a12-46b2-abc6-53fbc2a54...@googlegroups.com,
 8 Dihedral dihedral88...@gmail.com wrote:

 It is trivial to use UDP with 
 forward error correction such as 
 the CD in 1982.

CD uses Reed-Solomon coding, which is great for correcting the types of 
errors expected on a CD.  Namely, bursts of bit errors caused by 
localized failure of the optical coating, scratches, dirt, etc.  It 
wouldn't be hard to build something like that on top of UDP, but those 
sorts of errors are not what you typically see in networks.

It's relatively rare for a bit to get corrupted in a network packet.  
And, when it does, it's almost certainly caught by lower-level 
mechanisms such as ethernet frame CRC.  Much more likely is for a packet 
to get dropped because of queue overflow, or for sequential packets to 
arrive out of order due to multiple transmission paths with different 
latencies.  Those are the sorts of things TCP protects against.

Sure, you could implement retransmit timers and packet reordering in 
user code, but it would be distinctly non-trivial and ultimately you 
would end up reinventing most of TCP.  Except that your implementation 
would suck compared to the kernel algorithms which have been 
continuously tested and fine-tuned for the past 30 years.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-16 Thread Jean-Michel Pichavant


- Original Message -
 Op maandag 16 december 2013 13:05:41 UTC+1 schreef Jean-Michel
 Pichavant:
   Here is the code:
   #!/usr/bin/env python
   import telnetlib
   host = '10.128.59.63'
   port = 7000
   t = Telnet(host, port)
   t.write('*IDN?\n')
   print t.read_until('Whateverprompt')
   # you can use read_very_eager also
   
   and this is the result of executing the code(from which I deduce
   I
   have to
   install telnetlib, but how?)
   Traceback (most recent call last):
 File ./nctelnet.py, line 5, in module
   t = Telnet(host, port)
   NameError: name 'Telnet' is not defined
   
   kind regards,
   jean
  t = telnetlib.Telnet(host, port)
 this helps, but I don't know what to do with
 print t.read_until('Whateverprompt')
 
 should I send CTRL-ALT-ALTGR-] after some time?
 
 kind regards,
 jean

one way to approach the problem is to first make some monkey tests.
1/ connect to your equipment using telnet (from the linux shell)
2/ try typing some commands like *IDN?
3/ see how the equipment is answering
4/ you need to identify what is the prompt, and what EndOfLine sequence is used.
5/ then in a python shell, try to reproduce the behavior:

  import telnetlib
  t = telnetlib.Telnet(host, port)
  t.read_very_eager() #flush
  t.write('\n')
  prompt = t.read_very_eager() #this is one way to get the prompt
  print repr(prompt) #you may identify the EOL sequence with this one

When you get a good feeling about how it works, write the code.

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.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-16 Thread Jean Dubois
Op maandag 16 december 2013 15:16:17 UTC+1 schreef Jean-Michel Pichavant:
 - Original Message -
  Op maandag 16 december 2013 13:05:41 UTC+1 schreef Jean-Michel
  Pichavant:
Here is the code:
#!/usr/bin/env python
import telnetlib
host = '10.128.59.63'
port = 7000
t = Telnet(host, port)
t.write('*IDN?\n')
print t.read_until('Whateverprompt')
# you can use read_very_eager also

and this is the result of executing the code(from which I deduce
I
have to
install telnetlib, but how?)
Traceback (most recent call last):
  File ./nctelnet.py, line 5, in module
t = Telnet(host, port)
NameError: name 'Telnet' is not defined

kind regards,
jean
   t = telnetlib.Telnet(host, port)
  this helps, but I don't know what to do with
  print t.read_until('Whateverprompt')
  
  should I send CTRL-ALT-ALTGR-] after some time?
  
  kind regards,
  jean
 one way to approach the problem is to first make some monkey tests.
 1/ connect to your equipment using telnet (from the linux shell)
 2/ try typing some commands like *IDN?
 3/ see how the equipment is answering
 4/ you need to identify what is the prompt, and what EndOfLine sequence is 
 used.
 5/ then in a python shell, try to reproduce the behavior:
   import telnetlib
   t = telnetlib.Telnet(host, port)
   t.read_very_eager() #flush
   t.write('\n')
   prompt = t.read_very_eager() #this is one way to get the prompt
   print repr(prompt) #you may identify the EOL sequence with this one
 When you get a good feeling about how it works, write the code.
Running you code I get as response:
''


This is what I got using telnet:
[jean:~] $ telnet 10.128.59.63 7000
Trying 10.128.59.63...
Connected to 10.128.59.63.
Escape character is '^]'.
*IDN?
KEITHLEY INSTRUMENTS INC.,MODEL 2425,1078209,C32   Oct  4 2010
14:20:11/A02  /E/ 
 H

after pressing CTRL-ALT-ALTGR-] I get this:
^[^]
after which I get the telnet-prompt
telnet
and I can quit telnet by entering quit


kind regards,
jean
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-16 Thread Jean-Michel Pichavant
 This is what I got using telnet:
 [jean:~] $ telnet 10.128.59.63 7000
 Trying 10.128.59.63...
 Connected to 10.128.59.63.
 Escape character is '^]'.
 *IDN?
 KEITHLEY INSTRUMENTS INC.,MODEL 2425,1078209,C32   Oct  4 2010
 14:20:11/A02  /E/
  H
 
 after pressing CTRL-ALT-ALTGR-] I get this:
 ^[^]
 after which I get the telnet-prompt
 telnet
 and I can quit telnet by entering quit
 
 
 kind regards,
 jean
 --
 https://mail.python.org/mailman/listinfo/python-list


Looks like you don't have any prompt.
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?')


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.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-16 Thread Jean Dubois
Op maandag 16 december 2013 17:44:31 UTC+1 schreef Jean-Michel Pichavant:
  This is what I got using telnet:
  [jean:~] $ telnet 10.128.59.63 7000
  Trying 10.128.59.63...
  Connected to 10.128.59.63.
  Escape character is '^]'.
  *IDN?
  KEITHLEY INSTRUMENTS INC.,MODEL 2425,1078209,C32   Oct  4 2010
  14:20:11/A02  /E/
   H
  
  after pressing CTRL-ALT-ALTGR-] I get this:
  ^[^]
  after which I get the telnet-prompt
  telnet
  and I can quit telnet by entering quit
  
  
  kind regards,
  jean
  --
  https://mail.python.org/mailman/listinfo/python-list

 Looks like you don't have any prompt.
 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...

kind regards,
jean
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-16 Thread Chris Angelico
On Tue, Dec 17, 2013 at 5:26 AM, Jean Dubois jeandubois...@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
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-16 Thread Dave Angel
On Mon, 16 Dec 2013 10:26:14 -0800 (PST), Jean Dubois 
jeandubois...@gmail.com wrote:




  File ./test.py, line 7
def flush()
  ^
SyntaxError: invalid syntax


A definition line needs to end with a colon (fix the other as well)

--
DaveA

--
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-16 Thread Jean-Michel Pichavant


- Original Message -
 On Tue, Dec 17, 2013 at 5:26 AM, Jean Dubois
 jeandubois...@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.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-16 Thread Jean Dubois
Op maandag 16 december 2013 20:21:15 UTC+1 schreef Jean-Michel Pichavant:
 - Original Message -
  On Tue, Dec 17, 2013 at 5:26 AM, Jean Dubois
  jeandubois...@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 :)
I'm a newbie in Python programming that is very much true, and contrary to what 
you seem to suggest I did my homework: I succeeded
already in writing a Python-script which communicates directly over rs232 with 
the same device which I now am trying to connect to via a rs232-ethernet 
adapter.
So I thought it would be simply a matter of communicating the same commands as 
I did before.
Here are some parts of my code:
serkeith = serial.Serial('/dev/ttyUSB0', 9600, 8, timeout=5, xonxoff=1)
serkeith.write(*RST + \n)
#turn off concurrent functions
serkeith.write(:SENS:FUNC:CONC OFF + \n)
#current source function
serkeith.write(:SOUR:FUNC CURR + \n)
#volt sense function
serkeith.write(:SENS:FUNC 'VOLT:DC' + \n)
#105V compliance
#serkeith.write(:SENS:VOLT:PROT 105 + \n)
compliancestring=':SENS:VOLT:PROT '+str(compliancevalue) + '\n'
serkeith.write(compliancestring)
.
.
keithleymeasurement=serkeith.readline().split(',')

Also I got it working with nc and telnet, I just don't know how to accomplish 
this using python.
Tomorrow I'll look further at some a the more recent suggestions

kind regards,
jean
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-15 Thread Grant Edwards
On 2013-12-15, Dan Stromberg drsali...@gmail.com wrote:
 On Fri, Dec 13, 2013 at 8:06 AM, Grant Edwards invalid@invalid.invalid 
 wrote:
 On 2013-12-12, Dan Stromberg drsali...@gmail.com wrote:

 Just to be pedantic: _TCP_ sockets reserve 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.]

 I haven't done a lot of UDP, but are you pretty sure UDP can't at
 least fragment large packets?  What's a router or switch to do if the
 Path MTU isn't large enough for an original packet?

 http://www.gamedev.net/topic/343577-fragmented-udp-packets/

 You're conflating IP datagrams and Ethernet packets.  The IP stack can
 fragment an IP datagram into multiple Ethernet packets which are then
 reassembled by the receiving IP stack into a single datagram before
 being passed up to the next layer (in this case, UDP).

 As long as you're saying this of UDP, I have no problem with it.

That is indeed what I'm saying.  I apoligize if that was not clear in
my original posting.

 I've seen TCP fragment and not be reassembled though, which suggests
 to me that the reassembly's happening in UDP rather than IP.

That's something different.  In TCP, there's no guarantee that
reads/writes correspond 1:1 to IP datagrams.  TCP is a _stream_
protocol and there is no semantic meaning attached to the boundaries
between successive read/write calls the way there is with UDP.

 If it's done by IP the same way for UDP and TCP,

The IP layer is supposed to reassemble receive datagrams for both --
but that's got nothing to do with atomicity of TCP writes/reads.  The
TCP stack can (and often does) turn one write() call into multiple IP
datagrams.  It can also turn multiple writes into a singel IP
datagram.  On the other end, it can split up a single datagram into
multiple read()s and/or combined multiple datagrams into a single
read().  TCP is a stream service, not a datagram service like UDP.

 I'd not trust it in UDP either.

The standards all require UDP datagrams to be preserved.  All of the
UDP applications I've ever written or seen depend utterly on that, and
it's always worked that way for me.  If you've seen it fail, then you
ought to file a bug report.

 Did you read the thread you pointed to?  Your question was answerd by
 posting #4 in the thread you cited:

1) Yes, packets will be fragmented at the network layer (IP), but
   this is something you do not have to worry about since the
   network layer will reassemble the fragments before passing them
   back up to the transport layer (UDP). UDP garentees preserved
   message boundaries, so you never have to worry about only
   receiving a packet fragment :~).

 Actually, I believe the link I sent (which I skimmed) had people
 coming down on both sides of the matter.  Some said that UDP would be
 fine for small datagrams, while others said it would be fine,
 irrespective of size.

The maximum size of an IP datagram is 64KB, so it's not fine
irrespecive of size.  If your UDP implementation is working correctly
it will be fine below that limit.

 A few other references:

 http://tools.ietf.org/html/rfc791

  1.1. Motivation

   [...] The internet protocol provides for transmitting blocks of data
   called datagrams from sources to destinations, [...] The internet
   protocol also provides for fragmentation and reassembly of long
   datagrams, if necessary, for transmission through small packet
   networks.

 I've personally seen this fail to occur in TCP

You can't say that, because there's no correspondance between IP
datgrams and TCP read/write block sizes the way there is in UDP. 

With TCP there is nothing to fail (with respect to read/write block
sizes). TCP only guarantees that bytes will get there and get there in
the right order. It doesn't make any promises about block sizes.

 I've seen old time socket programmers explain that it cannot be relied
 upon in TCP; send() and recv() and (read() and write()) are system
 calls that return a length so that you can loop on them until all
 relevant data has been transferred.  They don't return that length
 just so you can ignore it.

That's true, but that's because of the design of the TCP _stream_
protocol, not because the IP datagram layer doesn't work right.

From the Socket HOWTO

 (http://docs.python.org/2/howto/sockets.html#socket-howto) : Now we
 come to the major stumbling block of sockets - send and recv operate
 on the network buffers. They do not necessarily handle all the bytes
 you hand them (or expect from them), because their major focus is
 handling the network buffers. In general, they return when the
 associated network buffers have been filled (send) or emptied (recv).
 They then tell you how many bytes they handled. It is your
 responsibility to call them again until your message has been
 completely dealt with.

If that's true for UDP, then the Python UDP implementation is broken,
and somebody 

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

2013-12-15 Thread Jean Dubois
Op zondag 15 december 2013 02:03:14 UTC+1 schreef Dan Stromberg:
 On Sat, Dec 14, 2013 at 5:33 AM, Jean Dubois jeandubois...@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 

-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-15 Thread Chris Angelico
On Mon, Dec 16, 2013 at 2:35 AM, Jean Dubois jeandubois...@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
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-15 Thread Roy Smith
In article l8kh1r$bj8$1...@reader1.panix.com,
 Grant Edwards invalid@invalid.invalid wrote:

 UDP is a a _datagram_ service. Either all the bytes in a write() 
 should get sent or none of them. Sending a paritial datagram is _not_ 
 a valid option.

I would agree with the above if you said send() instead of write().  
Python socket objects don't have write() methods, file objects do.  You 
can wrap a file around a socket with socket.makefile(), but I'm not sure 
I would expect the UDP record boundary semantics to be honored once you 
did that.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-15 Thread Chris Angelico
On Mon, Dec 16, 2013 at 2:51 AM, Roy Smith r...@panix.com wrote:
 In article l8kh1r$bj8$1...@reader1.panix.com,
  Grant Edwards invalid@invalid.invalid wrote:

 UDP is a a _datagram_ service. Either all the bytes in a write()
 should get sent or none of them. Sending a paritial datagram is _not_
 a valid option.

 I would agree with the above if you said send() instead of write().
 Python socket objects don't have write() methods, file objects do.  You
 can wrap a file around a socket with socket.makefile(), but I'm not sure
 I would expect the UDP record boundary semantics to be honored once you
 did that.

The underlying C API allows you, on Unix-like systems at least, to use
the standard write() function to send UDP packets (as long as you
first connect() - otherwise you need sendto() to specify a
destination). I don't usually use that method, but I would expect that
one call to write() becomes one UDP packet.

How that works with socket.makefile() in Python I have no idea.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-15 Thread Roy Smith
In article mailman.4143.1387123508.18130.python-l...@python.org,
 Chris Angelico ros...@gmail.com wrote:

 On Mon, Dec 16, 2013 at 2:51 AM, Roy Smith r...@panix.com wrote:
  In article l8kh1r$bj8$1...@reader1.panix.com,
   Grant Edwards invalid@invalid.invalid wrote:
 
  UDP is a a _datagram_ service. Either all the bytes in a write()
  should get sent or none of them. Sending a paritial datagram is _not_
  a valid option.
 
  I would agree with the above if you said send() instead of write().
  Python socket objects don't have write() methods, file objects do.  You
  can wrap a file around a socket with socket.makefile(), but I'm not sure
  I would expect the UDP record boundary semantics to be honored once you
  did that.
 
 The underlying C API allows you, on Unix-like systems at least, to use
 the standard write() function to send UDP packets (as long as you
 first connect() - otherwise you need sendto() to specify a
 destination). I don't usually use that method, but I would expect that
 one call to write() becomes one UDP packet.

At the Unix system call level, yes.  But, given that this is a Python 
newsgroup, I made the assumption we were talking about the Python API 
level.  Silly me :-)
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-15 Thread Dan Stromberg
On Sun, Dec 15, 2013 at 7:35 AM, Jean Dubois jeandubois...@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.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-15 Thread Grant Edwards
On 2013-12-15, Roy Smith r...@panix.com wrote:
 In article l8kh1r$bj8$1...@reader1.panix.com,
  Grant Edwards invalid@invalid.invalid wrote:

 UDP is a a _datagram_ service. Either all the bytes in a write() 
 should get sent or none of them. Sending a paritial datagram is _not_ 
 a valid option.

 I would agree with the above if you said send() instead of write().

Good point -- I meant send().  I keep forgetting that the libc socket
write() operation is missing in Python and only the send() call has
been made visible. In C write() and send() are effectively the same
thing (the parameters are arranged a little differently, but they
behave identically otherwise).

 Python socket objects don't have write() methods, file objects do.  You 
 can wrap a file around a socket with socket.makefile(), but I'm not sure 
 I would expect the UDP record boundary semantics to be honored once you 
 did that.

No, I wouldn't exect that.

-- 
Grant Edwards   grant.b.edwardsYow! I wish I was on a
  at   Cincinnati street corner
  gmail.comholding a clean dog!
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-15 Thread Chris Angelico
On Mon, Dec 16, 2013 at 9:42 AM, Grant Edwards invalid@invalid.invalid wrote:
 Good point -- I meant send().  I keep forgetting that the libc socket
 write() operation is missing in Python and only the send() call has
 been made visible. In C write() and send() are effectively the same
 thing (the parameters are arranged a little differently, but they
 behave identically otherwise).

Mostly - send() lets you set options, write() is equivalent to send()
with no options set. But other than that, they're identical, as stated
in man 2 send.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-14 Thread Jean Dubois
Op vrijdag 13 december 2013 18:09:50 UTC+1 schreef rusi:
 On Friday, December 13, 2013 5:50:03 PM UTC+5:30, Jean Dubois wrote:
  to make the script check itself whether pyhon2 or python3 should be used?
 As far as I know both (2 and 3) worked
 Do you have some reason to suspect one works and other not?

The reason I suggested this is that the script has #!/usr/bin/env python3
as the first line. When you have python2 installed and not python3 a
newbie will
probably not understand why it doesn't work.

kind regards,
jean

-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-14 Thread Jean Dubois
Op vrijdag 13 december 2013 09:35:18 UTC+1 schreef Mark Lawrence:
 On 13/12/2013 03:23, Jean Dubois wrote:
 
  kind regards,
  jean
  p.s. I'm using Linux/Kubuntu 11.04
 
 Would you please read and action this 
 https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the 
 double line spacing that accompanied the above, thanks.
I think I got it right this time. Thanks for helping me through it.

kind regards,
jean
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-14 Thread Mark Lawrence

On 14/12/2013 13:14, Jean Dubois wrote:

Op vrijdag 13 december 2013 09:35:18 UTC+1 schreef Mark Lawrence:

On 13/12/2013 03:23, Jean Dubois wrote:


kind regards,
jean
p.s. I'm using Linux/Kubuntu 11.04


Would you please read and action this
https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the
double line spacing that accompanied the above, thanks.

I think I got it right this time. Thanks for helping me through it.

kind regards,
jean



Yep, I've seen a couple of your posts that are just fine.  Thanks for 
taking these steps, I greatly appreciate your efforts.


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-14 Thread Jean Dubois
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


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

2013-12-14 Thread Dan Stromberg
On Sat, Dec 14, 2013 at 5:33 AM, Jean Dubois jeandubois...@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.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-14 Thread Dan Stromberg
On Fri, Dec 13, 2013 at 8:06 AM, Grant Edwards invalid@invalid.invalid wrote:
 On 2013-12-12, Dan Stromberg drsali...@gmail.com wrote:
 On Thu, Dec 12, 2013 at 6:16 AM, Grant Edwards invalid@invalid.invalid 
 wrote:

 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.]

 I haven't done a lot of UDP, but are you pretty sure UDP can't at
 least fragment large packets?  What's a router or switch to do if the
 Path MTU isn't large enough for an original packet?

 http://www.gamedev.net/topic/343577-fragmented-udp-packets/

 You're conflating IP datagrams and Ethernet packets.  The IP stack can
 fragment an IP datagram into multiple Ethernet packets which are then
 reassembled by the receiving IP stack into a single datagram before
 being passed up to the next layer (in this case, UDP).

As long as you're saying this of UDP, I have no problem with it.

I've seen TCP fragment and not be reassembled though, which suggests
to me that the reassembly's happening in UDP rather than IP.  If it's
done by IP the same way for UDP and TCP, I'd not trust it in UDP
either.

 Did you read the thread you pointed to?  Your question was answerd by
 posting #4 in the thread you cited:

1) Yes, packets will be fragmented at the network layer (IP), but this
   is something you do not have to worry about since the network
   layer will reassemble the fragments before passing them back up
   to the transport layer (UDP). UDP garentees preserved message
   boundaries, so you never have to worry about only receiving a
   packet fragment :~).

Actually, I believe the link I sent (which I skimmed) had people
coming down on both sides of the matter.  Some said that UDP would be
fine for small datagrams, while others said it would be fine,
irrespective of size.


 A few other references:

 http://tools.ietf.org/html/rfc791

  1.1. Motivation

   [...] The internet protocol provides for transmitting blocks of data
   called datagrams from sources to destinations, [...] The internet
   protocol also provides for fragmentation and reassembly of long
   datagrams, if necessary, for transmission through small packet
   networks.

I've personally seen this fail to occur in TCP - EG, it can cause a
stream of bytes to be written to tape with inconsistent block sizes if
transferred over rsh or ssh.  Usually the block sizes are consistent,
but not always.  Both SunOS 4.1.x and Ultrix had this issue; Ultrix
did it less often than SunOS, but Ultrix did do it.  I don't know for
certain if later *ix have the same issue, because I've been diligently
working around it ever since, but I suspect they do.

I've seen old time socket programmers explain that it cannot be relied
upon in TCP; send() and recv() and (read() and write()) are system
calls that return a length so that you can loop on them until all
relevant data has been transferred.  They don't return that length
just so you can ignore it.

From the Socket HOWTO
(http://docs.python.org/2/howto/sockets.html#socket-howto) :
Now we come to the major stumbling block of sockets - send and recv
operate on the network buffers. They do not necessarily handle all the
bytes you hand them (or expect from them), because their major focus
is handling the network buffers. In general, they return when the
associated network buffers have been filled (send) or emptied (recv).
They then tell you how many bytes they handled. It is your
responsibility to call them again until your message has been
completely dealt with.

HTH
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-13 Thread Mark Lawrence

On 13/12/2013 03:23, Jean Dubois wrote:


kind regards,
jean
p.s. I'm using Linux/Kubuntu 11.04



Would you please read and action this 
https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the 
double line spacing that accompanied the above, thanks.


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-13 Thread Jean Dubois
Op vrijdag 13 december 2013 04:32:30 UTC+1 schreef Dan Stromberg:
 On Thu, Dec 12, 2013 at 7:23 PM, Jean Dubois jeandubois...@gmail.com wrote:
 
  Op donderdag 12 december 2013 22:23:22 UTC+1 schreef Dan Stromberg:
 
  On Thu, Dec 12, 2013 at 12:28 AM, Jean Dubois jeandubois...@gmail.com 
  wrote:
 
 
 
   On Thursday, December 12, 2013 12:20:36 AM UTC+1, Dan Stromberg wrote:
 
 
 
   On Wed, Dec 11, 2013 at 3:08 PM, Jean Dubois jeandu...@gmail.com 
   wrote:
 
 
 
   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.
 
 
 
  Thank you very much for the example, the only trouble I'm having now is 
  installing the bufsock module:
 
  wget http://dcs.nac.uci.edu/~strombrg/bufsock.tar.gz
 
  results in The requested URL /~strombrg/bufsock.tar.gz was not found on 
  this server.
 
  Could you supply me the necessary installation instructions?
 
 
 
 That's an old link.  It's now at
 
 http://stromberg.dnsalias.org/~strombrg/bufsock.html
 
 
 
 HTH

I surfed to the new download-link  (http://stromberg.dnsalias.org/svn/bufsock/) 
but I don't see any instructions how to download or install
bufsock.py, I see it has something to do with svn which I don't know how to 
handle. Could you help me with that too?

thanks in advance
jean


http://stromberg.dnsalias.org/svn/bufsock/
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-13 Thread Jean Dubois
Op vrijdag 13 december 2013 04:32:30 UTC+1 schreef Dan Stromberg:
 On Thu, Dec 12, 2013 at 7:23 PM, Jean Dubois jeandubois...@gmail.com wrote:
 
  Op donderdag 12 december 2013 22:23:22 UTC+1 schreef Dan Stromberg:
 
  On Thu, Dec 12, 2013 at 12:28 AM, Jean Dubois jeandubois...@gmail.com 
  wrote:
 
 
 
   On Thursday, December 12, 2013 12:20:36 AM UTC+1, Dan Stromberg wrote:
 
 
 
   On Wed, Dec 11, 2013 at 3:08 PM, Jean Dubois jeandu...@gmail.com 
   wrote:
 
 
 
   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.
 
 
 
  Thank you very much for the example, the only trouble I'm having now is 
  installing the bufsock module:
 
  wget http://dcs.nac.uci.edu/~strombrg/bufsock.tar.gz
 
  results in The requested URL /~strombrg/bufsock.tar.gz was not found on 
  this server.
 
  Could you supply me the necessary installation instructions?
 
 
 
 That's an old link.  It's now at
 
 http://stromberg.dnsalias.org/~strombrg/bufsock.html
 
 
 
 HTH

I surfed to the new download-link  (http://stromberg.dnsalias.org/svn/bufsock/) 
but I don't see any instructions how to download or install
bufsock.py, I see it has something to do with svn which I don't know how to 
handle. Could you help me with that too?

thanks in advance
jean


http://stromberg.dnsalias.org/svn/bufsock/
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-13 Thread Jean Dubois
Op vrijdag 13 december 2013 09:35:18 UTC+1 schreef Mark Lawrence:

 Would you please read and action this 
 https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the 
 double line spacing that accompanied the above, thanks.

 -- 


 Mark Lawrence

Dear Mark,
I'm sorry for the inconvenience my postings may have caused. I now have
followed
the instructions on the link you mentioned and installed the plugin en
python-script.

hope it worked (I saw the text light up yellow when pressing the edit-key a 
second time). A small suggestion from a newbie: it would perhaps be possible
to make the script check itself whether pyhon2 or python3 should be used?

thanks for having patience with me
kind regards,
jean
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-13 Thread 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


-- 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.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-13 Thread Grant Edwards
On 2013-12-12, Dan Stromberg drsali...@gmail.com wrote:
 On Thu, Dec 12, 2013 at 6:16 AM, Grant Edwards invalid@invalid.invalid 
 wrote:

 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.]

 I haven't done a lot of UDP, but are you pretty sure UDP can't at
 least fragment large packets?  What's a router or switch to do if the
 Path MTU isn't large enough for an original packet?

 http://www.gamedev.net/topic/343577-fragmented-udp-packets/

You're conflating IP datagrams and Ethernet packets.  The IP stack can
fragment an IP datagram into multiple Ethernet packets which are then
reassembled by the receiving IP stack into a single datagram before
being passed up to the next layer (in this case, UDP).

Did you read the thread you pointed to?  Your question was answerd by
posting #4 in the thread you cited:

   1) Yes, packets will be fragmented at the network layer (IP), but this
  is something you do not have to worry about since the network
  layer will reassemble the fragments before passing them back up
  to the transport layer (UDP). UDP garentees preserved message
  boundaries, so you never have to worry about only receiving a
  packet fragment :~).


A few other references:

http://tools.ietf.org/html/rfc791

 1.1. Motivation

  [...] The internet protocol provides for transmitting blocks of data
  called datagrams from sources to destinations, [...] The internet
  protocol also provides for fragmentation and reassembly of long
  datagrams, if necessary, for transmission through small packet
  networks.
  
  [...]  

 1.4 Operation

  [...]
 
  The internet modules use fields in the internet header to fragment
  and reassemble internet datagrams when necessary for transmission
  through small packet networks.
  
  [...]

From http://en.wikipedia.org/wiki/IP_fragmentation  

  If a receiving host receives a fragmented IP packet, it has to
  reassemble the datagram and pass it to the higher protocol layer.
  Reassembly is intended to happen in the receiving host but in
  practice it may be done by an intermediate router, for example,
  network address translation may need to re-assemble fragments in
  order to translate data streams, e.g. the FTP control protocol, as
  described in RFC 2993
  
-- 
Grant Edwards   grant.b.edwardsYow! I'm continually AMAZED
  at   at th'breathtaking effects
  gmail.comof WIND EROSION!!
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-13 Thread Grant Edwards
On 2013-12-12, Chris Angelico ros...@gmail.com wrote:

 Now, if you want reliability AND datagrams, it's a lot easier to add
 boundaries to a TCP stream (sentinel or length prefixes) than to add
 reliability to UDP...

It's unfortunate that there's no standardized reliable
connection-oriented datagram protocol.  The linux kernel implements 
one for Unix domain sockets (SOCK_SEQPACKET), and its really, really
useful.

Adding boundaries to a TCP stream achieves the same goal (and isn't
that hard to do), but since there's no standard for it, people keep
having to reinvent it (often badly and always incompaibly).

-- 
Grant Edwards   grant.b.edwardsYow! Hello...  IRON
  at   CURTAIN?  Send over a
  gmail.comSAUSAGE PIZZA!  World War
   III?  No thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-13 Thread Chris Angelico
On Sat, Dec 14, 2013 at 3:10 AM, Grant Edwards invalid@invalid.invalid wrote:
 Adding boundaries to a TCP stream achieves the same goal (and isn't
 that hard to do), but since there's no standard for it, people keep
 having to reinvent it (often badly and always incompaibly).

Nearest to a standard would be the way heaps of internet protocols are
line-based - SMTP, POP, IMAP, FTP, and to a lesser extent HTTP as
well. The end-of-line sequence \r\n delimits messages.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-13 Thread Grant Edwards
On 2013-12-13, Chris Angelico ros...@gmail.com wrote:
 On Sat, Dec 14, 2013 at 3:10 AM, Grant Edwards invalid@invalid.invalid 
 wrote:
 Adding boundaries to a TCP stream achieves the same goal (and isn't
 that hard to do), but since there's no standard for it, people keep
 having to reinvent it (often badly and always incompaibly).

 Nearest to a standard would be the way heaps of internet protocols are
 line-based - SMTP, POP, IMAP, FTP, and to a lesser extent HTTP as
 well. The end-of-line sequence \r\n delimits messages.

And that works very nicely for things that transport text.  It's easy
to implement, easy to debug, easy to test.  But, when you need to
transport binary data, it gets ugly and compatibility problems start
to arise pretty quickly.

One could also borrow standards from the old-school serial world and
us the SYN/STX/ETX framing with byte stuffing used by HDLC et al.

-- 
Grant Edwards   grant.b.edwardsYow! My vaseline is
  at   RUNNING...
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-13 Thread rusi
On Friday, December 13, 2013 5:50:03 PM UTC+5:30, Jean Dubois wrote:
 Op vrijdag 13 december 2013 09:35:18 UTC+1 schreef Mark Lawrence:

  Would you please read and action this 
  https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the 
  double line spacing that accompanied the above, thanks.
  -- 

  Mark Lawrence

 Dear Mark,
 I'm sorry for the inconvenience my postings may have caused. I now have
 followed
 the instructions on the link you mentioned and installed the plugin en
 python-script.

Thanks for cooperating

 hope it worked (I saw the text light up yellow when pressing the edit-key a 
 second time). A small suggestion from a newbie: it would perhaps be possible
 to make the script check itself whether pyhon2 or python3 should be used?

Yes... Half way
The double-spacing problem is cured
However the long-lines remain (see your hope it worked... above)
Did you click the edit button both before and after your typing?

The 'before' should remove the double-spaced (old ...) lines
The 'after' should even out the right margins of what you've just typed

 thanks for having patience with me

Yes and you too please bear with us as we iron out this little irritant niggle

-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-13 Thread Chris Angelico
On Sat, Dec 14, 2013 at 3:57 AM, Grant Edwards invalid@invalid.invalid wrote:
 On 2013-12-13, Chris Angelico ros...@gmail.com wrote:
 On Sat, Dec 14, 2013 at 3:10 AM, Grant Edwards invalid@invalid.invalid 
 wrote:
 Adding boundaries to a TCP stream achieves the same goal (and isn't
 that hard to do), but since there's no standard for it, people keep
 having to reinvent it (often badly and always incompaibly).

 Nearest to a standard would be the way heaps of internet protocols are
 line-based - SMTP, POP, IMAP, FTP, and to a lesser extent HTTP as
 well. The end-of-line sequence \r\n delimits messages.

 And that works very nicely for things that transport text.  It's easy
 to implement, easy to debug, easy to test.  But, when you need to
 transport binary data, it gets ugly and compatibility problems start
 to arise pretty quickly.

 One could also borrow standards from the old-school serial world and
 us the SYN/STX/ETX framing with byte stuffing used by HDLC et al.

Yeah, or if it's a tight binary protocol with occasional bits of
bigger payload, either MIDI or TELNET could offer ideas. MIDI's SysEx
message can carry whatever is needed of it, and TELNET has
subnegotiation that can be used for the odd thingy or so. But for a
generic binary stream-of-messages pipe (as opposed to the
stream-of-bytes pipe that TCP normally offers), probably the easiest
is to precede each write with an N-byte length... and somehow
negotiate what N should be. (And endianness, but hopefully that's just
network byte order.)

Standards are awesome, there are so many to choose from! http://xkcd.com/927/

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-13 Thread rusi
On Friday, December 13, 2013 5:50:03 PM UTC+5:30, Jean Dubois wrote:
 to make the script check itself whether pyhon2 or python3 should be used?

As far as I know both (2 and 3) worked
Do you have some reason to suspect one works and other not?
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-12 Thread Jean Dubois
On Thursday, December 12, 2013 12:38:12 AM UTC+1, Conor Hughes wrote:
 Jean Dubois jeandubois...@gmail.com writes:
 
 
 
  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:
 
 
 
 In what way does it not work? Do you not get any data? Do you get the
 
 wrong data? Does your program block at a point which you do not
 
 understand?
 
 
 
 Probably more to the point, are you sure you are sending exactly the
 
 same data as you did with netcat? netcat running with stdin a terminal
 
 sends data line-by-line, and includes the newline in the data that it
 
 sends. You didn't send a newline in your example.
Thanks for the reply, I changed the line you mentioned to
s.send('*IDN?\n')
Rerunning the program then shows me as response the first time
Received:
The measurement instrument gives a beep indicating it receives something
which is however not recognized als normal input

Running the script a  second time, the program hangs.. and I have to reboot the 
adapter

kind regards,
jean
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-12 Thread Chris Angelico
On Thu, Dec 12, 2013 at 7:08 PM, Jean Dubois jeandubois...@gmail.com wrote:
 Thanks for the reply, I changed the line you mentioned to
 s.send('*IDN?\n')

See if there's a newline issue - you might need \r\n here.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-12 Thread Jean Dubois
On Thursday, December 12, 2013 12:20:36 AM UTC+1, Dan Stromberg wrote:
 On Wed, Dec 11, 2013 at 3:08 PM, Jean Dubois jeandu...@gmail.com 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

Dear Dan, 
Could you copy paste here the code for your function I have to add to my 
program?

thanks in advance
jean
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-12 Thread Jean Dubois
On Thursday, December 12, 2013 9:21:32 AM UTC+1, Chris Angelico wrote:
 On Thu, Dec 12, 2013 at 7:08 PM, Jean Dubois jeandubois...@gmail.com wrote:
 
  Thanks for the reply, I changed the line you mentioned to
 
  s.send('*IDN?\n')
 
 
 
 See if there's a newline issue - you might need \r\n here.
 
 
 
 ChrisA

I changed it as you suggested to:

 s.send('*IDN?\r\n')

unfortunately this doesn't change the result, first run give as response:
Received: 
second run makes the program hang and the adapter needs rebooting

kind regards,
jean
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-12 Thread Alister
On Thu, 12 Dec 2013 01:21:27 -0800, Jean Dubois wrote:

 On Thursday, December 12, 2013 9:21:32 AM UTC+1, Chris Angelico wrote:
 On Thu, Dec 12, 2013 at 7:08 PM, Jean Dubois jeandubois...@gmail.com
 wrote:
 
  Thanks for the reply, I changed the line you mentioned to
 
  s.send('*IDN?\n')
 
 
 
 See if there's a newline issue - you might need \r\n here.
 
 
 
 ChrisA
 
 I changed it as you suggested to:
 
  s.send('*IDN?\r\n')
 
 unfortunately this doesn't change the result, first run give as
 response:
 Received:
 second run makes the program hang and the adapter needs rebooting
 
 kind regards,
 jean

you probably need to use something like wireshark to see what is actually 
happening and compare it to a good connection in the normal way.




-- 
Save energy:  Drive a smaller shell.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-12 Thread Alister
On Thu, 12 Dec 2013 01:21:27 -0800, Jean Dubois wrote:

 On Thursday, December 12, 2013 9:21:32 AM UTC+1, Chris Angelico wrote:
 On Thu, Dec 12, 2013 at 7:08 PM, Jean Dubois jeandubois...@gmail.com
 wrote:
 
  Thanks for the reply, I changed the line you mentioned to
 
  s.send('*IDN?\n')
 
 
 
 See if there's a newline issue - you might need \r\n here.
 
 
 
 ChrisA
 
 I changed it as you suggested to:
 
  s.send('*IDN?\r\n')
 
 unfortunately this doesn't change the result, first run give as
 response:
 Received:
 second run makes the program hang and the adapter needs rebooting
 
 kind regards,
 jean

you probably need to use something like wireshark to see what is actually 
happening and compare it to a good connection in the normal way.




-- 
Save energy:  Drive a smaller shell.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-12 Thread Grant Edwards
On 2013-12-11, Dan Stromberg drsali...@gmail.com wrote:
 On Wed, Dec 11, 2013 at 3:08 PM, Jean Dubois jeandubois...@gmail.comwrote:

 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.edwardsYow! Those people look
  at   exactly like Donnie and
  gmail.comMarie Osmond!!
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-12 Thread Chris Angelico
On Fri, Dec 13, 2013 at 1:16 AM, Grant Edwards invalid@invalid.invalid wrote:
 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...

Or you write, write, write in quick succession. Nagle's Algorithm
means that if the first one hasn't yet been acknowledged, the second
one will be delayed, which means it'll probably be combined with the
third and sent when the first one's ACK comes through. Stream sockets
guarantee a stream of bytes; datagram sockets guarantee datagrams.
Weird how that goes, isn't it?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-12 Thread Mark Lawrence

On 12/12/2013 14:05, Alister wrote:


you probably need to use something like wireshark to see what is actually
happening and compare it to a good connection in the normal way.



You've sent this twice old chap, you've a configuration issue somewhere 
I'd guess :)


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-12 Thread Dan Stromberg
On Thu, Dec 12, 2013 at 12:28 AM, Jean Dubois jeandubois...@gmail.com wrote:
 On Thursday, December 12, 2013 12:20:36 AM UTC+1, Dan Stromberg wrote:
 On Wed, Dec 11, 2013 at 3:08 PM, Jean Dubois jeandu...@gmail.com 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

 Dear Dan,
 Could you copy paste here the code for your function I have to add to my 
 program?

This is untested, but it should be something like the following:

#!/usr/bin/env python


A simple echo client

import socket as socket_mod
import bufsock as bufsock_mod
host = '10.128.59.63'
port = 7000
size = 10
socket = socket_mod.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.connect((host,port))
bufsock = bufsock_mod.bufsock(socket)
bufsock.send('*IDN?')
data = bufsock.recv(size)
bufsock.close()
print 'Received:', data

You might look over
http://stackoverflow.com/questions/19918307/retrieve-file-information-located-on-a-different-application-server-using-python/19918706#19918706
for a more complete example.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-12 Thread Dan Stromberg
On Thu, Dec 12, 2013 at 6:16 AM, Grant Edwards invalid@invalid.invalid wrote:

 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.]

I haven't done a lot of UDP, but are you pretty sure UDP can't at
least fragment large packets?  What's a router or switch to do if the
Path MTU isn't large enough for an original packet?

http://www.gamedev.net/topic/343577-fragmented-udp-packets/
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-12 Thread Chris Angelico
On Fri, Dec 13, 2013 at 8:27 AM, Dan Stromberg drsali...@gmail.com wrote:
 On Thu, Dec 12, 2013 at 6:16 AM, Grant Edwards invalid@invalid.invalid 
 wrote:

 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.]

 I haven't done a lot of UDP, but are you pretty sure UDP can't at
 least fragment large packets?  What's a router or switch to do if the
 Path MTU isn't large enough for an original packet?

 http://www.gamedev.net/topic/343577-fragmented-udp-packets/

I'm no expert on this (mostly I do TCP, or UDP with fairly small
packets), but the packet should be reassembled at the far end. When
your application comes to receive it, it'll receive the entire UDP
packet as a whole.

UDP fragmentation has several problems. First, if any fragment is
lost, it won't be retransmitted (as TCP will), so the whole datagram
is lost. And secondly, if you stream data across the network in a
series of packets just a little too large to fit, each one will get
split in two and you'll end up with twice as many packets going out,
ergo abysmal performance. With TCP, there's the chance that the sender
and receiver can between them figure out what packet size to use (cf
path MTU discovery), but that won't happen with UDP unless the
application consciously does it. So it's something to be cautious of
in terms of performance, but if you want to send large UDP packets
because they make sense, just go ahead and do it.

Now, if you want reliability AND datagrams, it's a lot easier to add
boundaries to a TCP stream (sentinel or length prefixes) than to add
reliability to UDP...

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-12 Thread Christian Gollwitzer

Am 12.12.13 00:08, schrieb Jean Dubois:

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:



import socket
host = '10.128.59.63'
port = 7000
size = 10


The socket library advises to use a small power of two like 1024; 10 
seems very small.



s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host,port))
s.send('*IDN?')
\n or \r\n is missing, you found this by yourself - look into the device 
manual, which one is correct



data = s.recv(size)


It may be, that you simply need to wait for some time after the write, 
before you read. And then before the device is ready, you close the 
connection. If this is the case, try waiting a short time in between and 
use socket.sendall() instead of socket.send()



s.close()


Maybe you need to read twice?


Can anyone here tell me how to do it properly?


The most proper way is to use asynchronous IO; never done this in python 
before, check this:


http://docs.python.org/2/library/asyncore.html#asyncore-example-basic-http-client

Christian
--
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-12 Thread Dave Angel
On Thu, 12 Dec 2013 13:27:16 -0800, Dan Stromberg 
drsali...@gmail.com wrote:
On Thu, Dec 12, 2013 at 6:16 AM, Grant Edwards 

invalid@invalid.invalid wrote:

I haven't done a lot of UDP, but are you pretty sure UDP can't at
least fragment large packets?  What's a router or switch to do if 

the

Path MTU isn't large enough for an original packet?


A router doesn't talk udp or tcp, it deals with ip packets, which it 
IS permitted to fragment. 


Conversely the udp layer in the os doesn't care about MTU.

--
DaveA

--
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-12 Thread Jean Dubois
Op donderdag 12 december 2013 22:23:22 UTC+1 schreef Dan Stromberg:
 On Thu, Dec 12, 2013 at 12:28 AM, Jean Dubois jeandubois...@gmail.com wrote:
 
  On Thursday, December 12, 2013 12:20:36 AM UTC+1, Dan Stromberg wrote:
 
  On Wed, Dec 11, 2013 at 3:08 PM, Jean Dubois jeandu...@gmail.com 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
 
 
 
  Dear Dan,
 
  Could you copy paste here the code for your function I have to add to my 
  program?
 
 
 
 This is untested, but it should be something like the following:
 
 
 
 #!/usr/bin/env python
 
 
 
 
 
 A simple echo client
 
 
 
 import socket as socket_mod
 
 import bufsock as bufsock_mod
 
 host = '10.128.59.63'
 
 port = 7000
 
 size = 10
 
 socket = socket_mod.socket(socket.AF_INET, socket.SOCK_STREAM)
 
 socket.connect((host,port))
 
 bufsock = bufsock_mod.bufsock(socket)
 
 bufsock.send('*IDN?')
 
 data = bufsock.recv(size)
 
 bufsock.close()
 
 print 'Received:', data
 
 
 
 You might look over
 
 http://stackoverflow.com/questions/19918307/retrieve-file-information-located-on-a-different-application-server-using-python/19918706#19918706
 
 for a more complete example.

Thank you very much for the example, the only trouble I'm having now is 
installing the bufsock module:
wget http://dcs.nac.uci.edu/~strombrg/bufsock.tar.gz 
results in The requested URL /~strombrg/bufsock.tar.gz was not found on this 
server.
Could you supply me the necessary installation instructions?

kind regards,
jean
p.s. I'm using Linux/Kubuntu 11.04
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-12 Thread Dan Stromberg
On Thu, Dec 12, 2013 at 7:23 PM, Jean Dubois jeandubois...@gmail.com wrote:
 Op donderdag 12 december 2013 22:23:22 UTC+1 schreef Dan Stromberg:
 On Thu, Dec 12, 2013 at 12:28 AM, Jean Dubois jeandubois...@gmail.com 
 wrote:

  On Thursday, December 12, 2013 12:20:36 AM UTC+1, Dan Stromberg wrote:

  On Wed, Dec 11, 2013 at 3:08 PM, Jean Dubois jeandu...@gmail.com wrote:

  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.

 Thank you very much for the example, the only trouble I'm having now is 
 installing the bufsock module:
 wget http://dcs.nac.uci.edu/~strombrg/bufsock.tar.gz
 results in The requested URL /~strombrg/bufsock.tar.gz was not found on this 
 server.
 Could you supply me the necessary installation instructions?

That's an old link.  It's now at
http://stromberg.dnsalias.org/~strombrg/bufsock.html

HTH
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-11 Thread Dan Stromberg
On Wed, Dec 11, 2013 at 3:08 PM, Jean Dubois jeandubois...@gmail.comwrote:

 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
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2013-12-11 Thread Conor Hughes
Jean Dubois jeandubois...@gmail.com writes:

 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:

In what way does it not work? Do you not get any data? Do you get the
wrong data? Does your program block at a point which you do not
understand?

Probably more to the point, are you sure you are sending exactly the
same data as you did with netcat? netcat running with stdin a terminal
sends data line-by-line, and includes the newline in the data that it
sends. You didn't send a newline in your example.
-- 
https://mail.python.org/mailman/listinfo/python-list