Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 11-12 of 12 total

Discover bluetooth devices around you

Pys60 has good bluetooth support from the beginning.
However, to discover another device, it require you to
interact with the app, choosing a device from the list.
PDIS has a library that help you list all devices silently.
   1  
   2  # need to install these 2 modules from PDIS first
   3  import aosocketnativenew
   4  from aosocket.symbian.bt_device_discoverer import *
   5  
   6  def callback(error, devices, cb_param=None):
   7      for address, name in devices:      
   8          print "Found: ", name, address
   9  # You can get more data by importing socket and try 
  10  # bt_discover(address) or bt_obex_discover(address)
  11  # see details in official pys60 doc on socket module
  12  
  13  lister = BtDeviceLister()
  14  lister.discover_all(callback, None)

I summarize the code above from thejamo's example here.
His code is more complete with error checking.

Using socket datagrams

From Jeff Bauer's recipe.
   1  
   2  # server.py
   3  import socket
   4  port = 8081
   5  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
   6  s.bind(("", port))
   7  print "waiting on port:", port
   8  while 1:
   9      data, addr = s.recvfrom(1024)
  10      print data

   1  
   2  # client.py
   3  import socket
   4  port = 8081
   5  host = "localhost"
   6  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
   7  s.bind(("", 0))
   8  s.sendto("Holy Guido! It's working.", (host, port))
« Newer Snippets
Older Snippets »
Showing 11-12 of 12 total