what said in the API document
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
settimeout(timeout)
settimeout(timeout)
Set a timeout on socket operations. 'timeout' can be a float,
giving in seconds, or None. Setting a timeout of None disables
the timeout feature and is equivalent to setblocking(1).
Setting a timeout of zero is the same as setblocking(0).
If a timeout is set, the connect, accept, send and receive operations will raise ((( socket.timeout))) if a timeout occurs.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Best Regards!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
when I run the code in terminal,it give me message like this:
Traceback (most recent call last):
File "test.py", line 30, in <module>
except socket.timeout:
AttributeError: 'function' object has no attribute 'timeout'
But I find socket object have the attribute of timeout,in other's application I found the code "except socket.timeout",why it not working here?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The problem with the code you were trying was that it was trying to get the 'timeout' class from the 'socket' function in lightblue, instead of the 'socket' module in the standard library. This code fixes the problem by explicitly stating where 'timeout' comes from.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
thank you Blam,I followed what you said and get the result below:
Traceback (most recent call last):
File "aa.py", line 11, in <module>
lightblue.obex.recvfile(s,"test.txt")
File "/usr/lib/python2.5/site-packages/lightblue/_obex.py", line 368, in recvfile
conn, addr = sock.accept()
File "/usr/lib/python2.5/site-packages/lightblue/_lightblue.py", line 161, in accept
raise _socket.error(str(e))
socket.error: timed out
Source Code is :
#!/usr/bin/python
#-*-coding:utf8-*-
I'll fix it in the next release. In the meantime, you can get it working in your own version by fixing src/linux/_lightblue.py. Just change lines 160-163 from this:
hi!
I just can't get the right error symbol that when a socket time out error raised,in below code I just follow the API document but it seems not work.
my code is below:
**************************************************
from lightblue import *
s = socket()
s.bind(("",0))
advertise("My OBEX Service",s,OBEX)
s.settimeout(1)
try:
obex.recvfile(s,"test.txt")
except socket.timeout:
print ">>>time out,receive failed!"
s.close()
**************************************************
what said in the API document
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
settimeout(timeout)
settimeout(timeout)
Set a timeout on socket operations. 'timeout' can be a float,
giving in seconds, or None. Setting a timeout of None disables
the timeout feature and is equivalent to setblocking(1).
Setting a timeout of zero is the same as setblocking(0).
If a timeout is set, the connect, accept, send and receive operations will raise ((( socket.timeout))) if a timeout occurs.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Best Regards!
when I run the code in terminal,it give me message like this:
Traceback (most recent call last):
File "test.py", line 30, in <module>
except socket.timeout:
AttributeError: 'function' object has no attribute 'timeout'
But I find socket object have the attribute of timeout,in other's application I found the code "except socket.timeout",why it not working here?
The soft I have installed is bellow:
openobex 1.3-3
python-bluez 0.14-1
python 2.5
lightblue 0.3.2
ubuntu 8.04
Hi,
Sorry for the late reply.
Try this instead:
import lightblue
import socket
s = lightblue.socket()
s.bind(("",0))
lightblue.advertise("My OBEX Service",s, lightblue.OBEX)
s.settimeout(1)
try:
lightblue.obex.recvfile(s,"test.txt")
except socket.timeout:
print ">>>time out,receive failed!"
s.close()
The problem with the code you were trying was that it was trying to get the 'timeout' class from the 'socket' function in lightblue, instead of the 'socket' module in the standard library. This code fixes the problem by explicitly stating where 'timeout' comes from.
thank you Blam,I followed what you said and get the result below:
Traceback (most recent call last):
File "aa.py", line 11, in <module>
lightblue.obex.recvfile(s,"test.txt")
File "/usr/lib/python2.5/site-packages/lightblue/_obex.py", line 368, in recvfile
conn, addr = sock.accept()
File "/usr/lib/python2.5/site-packages/lightblue/_lightblue.py", line 161, in accept
raise _socket.error(str(e))
socket.error: timed out
Source Code is :
#!/usr/bin/python
#-*-coding:utf8-*-
import lightblue
import socket
s = lightblue.socket()
s.bind(("",0))
lightblue.advertise("My OBEX Service",s, lightblue.OBEX)
s.settimeout(1)
try:
lightblue.obex.recvfile(s,"test.txt")
except socket.timeout:
print ">>>time out,receive failed!"
s.close()
it seems not work correctly,and I'm really new to Linux,please help me,thanks!
Darn, that is a bug in LightBlue.
I'll fix it in the next release. In the meantime, you can get it working in your own version by fixing src/linux/_lightblue.py. Just change lines 160-163 from this:
except _bluetooth.error, e:
raise _socket.error(str(e))
except _bluetooth.timeout, te:
raise _socket.timeout(str(te))
to this:
except _bluetooth.timeout, te:
raise _socket.timeout(str(te))
except _bluetooth.error, e:
raise _socket.error(str(e))
Thanks for finding this bug.
Yeah,It works,thank you Blam!^_^