Results 1 to 3 of 3

Thread: Python3.3 Sockets AF_BLUETOOTH

  1. #1
    Join Date
    Oct 2007
    Location
    Kentucky, USA
    Beans
    731
    Distro
    Ubuntu

    Python3.3 Sockets AF_BLUETOOTH

    When creating an AF_BLUETOOTH socket, does one need to connect to the receiving server before sending or can one simply send the data?
    Which is more important in obtaining the truth, "what" or "why"? Trick question. They are of equal importance.
    Freely ye have received, freely give.

  2. #2
    Join Date
    Jun 2009
    Location
    Land of Paranoia and Guns
    Beans
    194
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Re: Python3.3 Sockets AF_BLUETOOTH

    Although I'm not too familiar with Bluetooth, I'm pretty sure any socket made with socket.socket uses the same abstraction. You need to connect first with socket.connect before using socket.send and socket.recv. I have no idea how you would discover other devices and set up a pairing, though.
    Don't use W3Schools as a resource! (Inconsequential foul language at the jump)
    Open Linux Forums (More foul language, but well worth it for the quality of support and good humor.)
    If you want to discuss W3Schools, please PM me instead of posting.

  3. #3
    Join Date
    Oct 2007
    Location
    Kentucky, USA
    Beans
    731
    Distro
    Ubuntu

    Re: Python3.3 Sockets AF_BLUETOOTH

    Sorry, wrong terminology. I meant was a pair required to send data. I'm working on a library and have already accomplish scanning by PIPING out the results of "hcitool scan." It creates a nice list of devices and their device names. This is it so far. I need to know if I can just send the data or if I also must pair the devices. Having only one bluetooth device, I cannot test it.

    Code:
    class tools():
    	def scan(self):
    		a = subprocess.Popen(["hcitool", "scan"], stdout = subprocess.PIPE).communicate()[0].split()[2:]
    		if a == []:
    			return "ERROR: Device appears to be turned off or not working. Try a device reset \"sudo hciconfig hci0 reset\""
    		else:
    			return a
    
    	def send(self, mac, port, string):
    		b = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
    		b.connect((mac, port))
    		b.send(bytes(string, "UTF-8"))
    		b.close()
    Which is more important in obtaining the truth, "what" or "why"? Trick question. They are of equal importance.
    Freely ye have received, freely give.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •