help with threads and obexftp push

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2009
Posts: 1
Reputation: luiss is an unknown quantity at this point 
Solved Threads: 0
luiss luiss is offline Offline
Newbie Poster

help with threads and obexftp push

 
0
  #1
Sep 23rd, 2009
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.

  1. import time
  2. import obexftp
  3. import threading
  4.  
  5. def discover():
  6. cli = obexftp.client(obexftp.BLUETOOTH)
  7. clientes = cli.discover()
  8. radios = len(clientes)
  9. cli.disconnect()
  10. cli.delete
  11. return clientes
  12.  
  13. class pushfile(threading.Thread):
  14. def __init__(self,mac):
  15. threading.Thread.__init__(self)
  16. self.mac = mac
  17.  
  18. def run(self):
  19. cli = obexftp.client(obexftp.BLUETOOTH)
  20. canal = obexftp.browsebt(self.mac,obexftp.PUSH)
  21. time.sleep(1)
  22. print "Connected to push channel: ",canal," of: ",self.mac
  23. time.sleep(1)
  24.  
  25. cli.connectpush(self.mac,canal,'hci2')
  26. print "Sending file to: %s" % self.mac
  27. enviado = cli.put_file("filename.jpg")
  28. if enviado == 1:
  29. print "Send to: %s" % self.mac
  30. cli.disconnect()
  31. cli.delete
  32. time.sleep(1)
  33.  
  34. start = time.time()
  35. devicelist = []
  36.  
  37. dispositivos = discover()
  38. radios = len(dispositivos)
  39. print dispositivos
  40. print radios
  41.  
  42. for i in range(radios):
  43. mac = dispositivos[i]
  44. t = pushfile(mac)
  45. devicelist.append(t)
  46. t.start()
  47.  
  48. for push in devicelist:
  49. push.join()
  50. print "Thread ended for: ",push.mac
  51.  
  52. print "Elapsed Time: %s" % (time.time() - start)
Reply With Quote Quick reply to this message  
Reply

Tags
bluetooth, obexftp, push, python

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 557 | Replies: 0
Thread Tools Search this Thread



Tag cloud for bluetooth, obexftp, push, python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC