Socket stream

David Bolen db3l at fitlinxx.com
Tue Feb 26 19:15:07 EST 2002


Christian Maus <maus at netz.klinik.uni-mainz.de> writes:

> Hello,
> 
> I try to control a device via a com server. Setting a command to the device 
> works fine, but when I try to read the answer, my loop for reading from the 
> socket does not terminate. My loop looks like this:
> 
> while 1:
>        data = sockobj.recv(1024)
>        if not data: break
>        print data
> sockobj.close()
> 
> I get the output:
(...)
> and then I'm stuck in the loop. Any idea what the problem is?

If there is no data on the socket and you issue a recv() it will block
until data arrives.  I don't know your device protocol but you don't
seem to have a termination condition in your loop.  You probably want
to detect when the device has completed sending you information and
exit the loop on that condition, rather than looking for an empty
string (which should only happen when the other end closes down the
socket).

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list