[PythonCE] Re: no select module
Guido Wesdorp
mailings at johnnydebris.net
Tue Dec 2 05:58:29 EST 2003
Browsing through the manual I noticed how the select module can only be
used for real socket objects in Windows, so therefore I assume your code
doesn't do anything special. I rewrote the last piece of code so it uses
plain sockets instead of select, I think you can replace the first bit
by the same piece of code (perhaps with some name changes or so). Note
that the code hasn't been tested (although it should work) and it
requires Python 2.3 (because of the timeout stuff).
>> -----------------
>> soc = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
>> soc.connect((HOSTNAME, PORT))
>> soc.send(data)
>> rlist, wlist, elist = select.select([soc], [], [], 15)
>> if rlist:
>> answer = soc.recv(9999)
>> return answer
>> soc.close()
>> -----------------
>
-------------------------------------------------------------------------------------------------
# plain socket replacement of the select stuff
soc = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
soc.connect((HOSTNAME, PORT))
soc.send(data)
socket.settimeout(15)
try:
answer = soc.recv(1)
except socket.timeout:
soc.close()
else:
soc.setblocking(0)
answer += soc.recv(9999)
soc.settimeout(None)
soc.setblocking(1)
return answer
-------------------------------------------------------------------------------------------------
If you're done replacing the code, you can remove the 'import select'
statements from your script and it should work again.
Cheers,
Guido
More information about the PythonCE
mailing list