My application needs opening a obex service, receiving a file, and stopping the service while it's processing the incoming file, then reopen the service after the processing is over.
Error is raised like this in second round running:
Traceback (most recent call last):
File "test1.py", line 7, in <module>
advertise("LanvinCell Here!", bt_socket, OBEX)
File "/usr/lib/python2.5/site-packages/lightblue/_lightblue.py", line 257, in advertise
raise _lightbluecommon.BluetoothError(str(e))
lightblue._lightbluecommon.BluetoothError: (77, 'File descriptor in bad state')
Traceback (most recent call last):
File "test1.py", line 6, in <module>
bt_socket.bind(("00:13:8A:40:38:27",9))
File "<string>", line 5, in bind
socket.error: (98, 'Address already in use')
Help me please.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It looks like there is a bug in _lightblue.py that is stopping your first code snippet from working. I'll fix this in the next release, but for now I've pasted a patch below that you can apply to src/linux/_lightblue.py to fix this.
The second code snippet should work, though ... perhaps it is a timing issue. Try waiting a few seconds after you close() the socket to make sure the channel is released before you bind() the socket the next time around.
Here is a patch to make the first code snippet work:
def getsockname(self):
sockname = self._sock.getsockname()
@@ -231,7 +236,8 @@
# obex.recvfile() docs state that an obex server socket should
# *not* be listening before recvfile() is called (due to Series60's
# particular implementation)
- sock.listen(1)
+ if not sock._listening:
+ sock.listen(1)
# advertise Object Push Profile not File Transfer Profile because
# obex.recvfile() implementations run OBEX servers which only
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What I want to do is using multi-socket in a bluetooth dongle, but whatever I tried, when I bound second socket with the dongle, it raised 'Address already in use' error. Waiting for 10 more seconds will not solve the problem. it seems that the bound address is locked somewhere, and couldn't be used until it is released.
I have successfully bound multi-socket with a bluetooth dongle in case of not specifying the device's address, but that solution is not ok for me because I am going to use multi-dongle in my application.
So, how to use mutli-socket( or multi-receiving-channel) in multi-device situation without 'Address already in use' problem? is there any solution?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm not sure about this. I haven't got multiple adapters at the moment for testing this, and I don't know why you wouldn't be able to bind to the second adapter. I suppose it doesn't make a difference what channel you bind to on the second adapter? So once you have bound to any channel on the first adapter, you cannot bind to any channel on the second adapter at all?
Are you still unable to run the second code snippet you included in your first post? I was able to run this without any problems (although I only have one adapter plugged in). If you can't run that even with one adapter, it would seem that there are problems with releasing the channel, even with only one adapter in use.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The snippet you provided works well when there is only ONE socket bound to the adapter, that is a good prograss, but it fails with 'Address already in use' error when I try to bind second socket to the adapter. Can you bind two more sockets to a adapter address without any problem? that's what I wanted.
You are so patient wtih me, thank you!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
My application needs opening a obex service, receiving a file, and stopping the service while it's processing the incoming file, then reopen the service after the processing is over.
First, I do it in this way:
bt_socket=socket()
bt_socket.bind(("00:13:8A:40:38:27",9))
while 1:
advertise("LanvinCell Here!", bt_socket, OBEX)
obex.recvfile(bt_socket, "text.txt")
stopadvertise(bt_socket)
Error is raised like this in second round running:
Traceback (most recent call last):
File "test1.py", line 7, in <module>
advertise("LanvinCell Here!", bt_socket, OBEX)
File "/usr/lib/python2.5/site-packages/lightblue/_lightblue.py", line 257, in advertise
raise _lightbluecommon.BluetoothError(str(e))
lightblue._lightbluecommon.BluetoothError: (77, 'File descriptor in bad state')
next I try on another approach:
while 1:
bt_socket=socket()
bt_socket.bind(("00:13:8A:40:38:27",9))
advertise("LanvinCell Here!", bt_socket, OBEX)
obex.recvfile(bt_socket, "text.txt")
stopadvertise(bt_socket)
bt_socket.close()
A new error rasied in second round running:
Traceback (most recent call last):
File "test1.py", line 6, in <module>
bt_socket.bind(("00:13:8A:40:38:27",9))
File "<string>", line 5, in bind
socket.error: (98, 'Address already in use')
Help me please.
Hi,
It looks like there is a bug in _lightblue.py that is stopping your first code snippet from working. I'll fix this in the next release, but for now I've pasted a patch below that you can apply to src/linux/_lightblue.py to fix this.
The second code snippet should work, though ... perhaps it is a timing issue. Try waiting a few seconds after you close() the socket to make sure the channel is released before you bind() the socket the next time around.
Here is a patch to make the first code snippet work:
--- _lightblue.py 2007-12-26 12:29:17.000000000 +1000
+++ /usr/lib/python2.4/site-packages/lightblue/_lightblue.py 2007-12-26 12:36:05.000000000 +1000
@@ -151,6 +151,7 @@
def __init__(self, sock):
self.__dict__["_sock"] = sock
self.__dict__["_advertised"] = False
+ self.__dict__["_listening"] = False
# must implement accept() to return _SocketWrapper objects
def accept(self):
@@ -172,6 +173,10 @@
def dup(self):
return _SocketWrapper(self._sock.dup())
dup.__doc__ = _lightbluecommon._socketdocs["dup"]
+
+ def listen(self, backlog):
+ self._sock.listen(backlog)
+ self._listening = True
def getsockname(self):
sockname = self._sock.getsockname()
@@ -231,7 +236,8 @@
# obex.recvfile() docs state that an obex server socket should
# *not* be listening before recvfile() is called (due to Series60's
# particular implementation)
- sock.listen(1)
+ if not sock._listening:
+ sock.listen(1)
# advertise Object Push Profile not File Transfer Profile because
# obex.recvfile() implementations run OBEX servers which only
The patch works, thank you!
What I want to do is using multi-socket in a bluetooth dongle, but whatever I tried, when I bound second socket with the dongle, it raised 'Address already in use' error. Waiting for 10 more seconds will not solve the problem. it seems that the bound address is locked somewhere, and couldn't be used until it is released.
I have successfully bound multi-socket with a bluetooth dongle in case of not specifying the device's address, but that solution is not ok for me because I am going to use multi-dongle in my application.
So, how to use mutli-socket( or multi-receiving-channel) in multi-device situation without 'Address already in use' problem? is there any solution?
I'm not sure about this. I haven't got multiple adapters at the moment for testing this, and I don't know why you wouldn't be able to bind to the second adapter. I suppose it doesn't make a difference what channel you bind to on the second adapter? So once you have bound to any channel on the first adapter, you cannot bind to any channel on the second adapter at all?
Are you still unable to run the second code snippet you included in your first post? I was able to run this without any problems (although I only have one adapter plugged in). If you can't run that even with one adapter, it would seem that there are problems with releasing the channel, even with only one adapter in use.
The snippet you provided works well when there is only ONE socket bound to the adapter, that is a good prograss, but it fails with 'Address already in use' error when I try to bind second socket to the adapter. Can you bind two more sockets to a adapter address without any problem? that's what I wanted.
You are so patient wtih me, thank you!
No problem at all.
What I meant was, this code works for me:
while 1:
bt_socket=socket()
bt_socket.bind(("00:13:8A:40:38:27",9))
advertise("LanvinCell Here!", bt_socket, OBEX)
obex.recvfile(bt_socket, "text.txt")
stopadvertise(bt_socket)
bt_socket.close()
I don't get the "Address already in use" error.
I can also bind another socket to the adapter on a different channel.