Hello all,
I recently started using Python to test a Bluetooth Push application prototype and everything was working great until threading. I wonder if someone knows how to start multiple threads of connectpush() with Obexftp running under Linux?
So far with the code below I have to wait until the first client connection gets close to start the next connection and I need to start many push connections at once.
The strange part is that the threads are working for obexftp.browsebt() method so I get push channels in every
thread or maybe it's because we don't need to accept or deny a connection to read a push channel in a Bluetooth device.
Thank you for your help
Luis S.
import time
import obexftp
import threading
def discover():
cli = obexftp.client(obexftp.BLUETOOTH)
clientes = cli.discover()
radios = len(clientes)
cli.disconnect()
cli.delete
return clientes
class pushfile(threading.Thread):
def __init__(self,mac):
threading.Thread.__init__(self)
self.mac = mac
def run(self):
cli = obexftp.client(obexftp.BLUETOOTH)
canal = obexftp.browsebt(self.mac,obexftp.PUSH)
time.sleep(1)
print "Connected to push channel: ",canal," of: ",self.mac
time.sleep(1)
cli.connectpush(self.mac,canal,'hci2')
print "Sending file to: %s" % self.mac
enviado = cli.put_file("filename.jpg")
if enviado == 1:
print "Send to: %s" % self.mac
cli.disconnect()
cli.delete
time.sleep(1)
start = time.time()
devicelist = []
dispositivos = discover()
radios = len(dispositivos)
print dispositivos
print radios
for i in range(radios):
mac = dispositivos[i]
t = pushfile(mac)
devicelist.append(t)
t.start()
for push in devicelist:
push.join()
print "Thread ended for: ",push.mac
print "Elapsed Time: %s" % (time.time() - start)