diff options
| author | Tim Redfern <tim@eclectronics.org> | 2011-12-19 18:20:33 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2011-12-19 18:20:33 +0000 |
| commit | e9a73bbb3c14af340999f70146747787785f4fee (patch) | |
| tree | a125452f7d641673286542497da051b810427880 /pybluez/simple/rfcomm-client.py | |
initial commit
Diffstat (limited to 'pybluez/simple/rfcomm-client.py')
| -rw-r--r-- | pybluez/simple/rfcomm-client.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/pybluez/simple/rfcomm-client.py b/pybluez/simple/rfcomm-client.py new file mode 100644 index 0000000..4da12af --- /dev/null +++ b/pybluez/simple/rfcomm-client.py @@ -0,0 +1,45 @@ +# file: rfcomm-client.py +# auth: Albert Huang <albert@csail.mit.edu> +# desc: simple demonstration of a client application that uses RFCOMM sockets +# intended for use with rfcomm-server +# +# $Id: rfcomm-client.py 424 2006-08-24 03:35:54Z albert $ + +from bluetooth import * +import sys + +addr = None + +if len(sys.argv) < 2: + print "no device specified. Searching all nearby bluetooth devices for" + print "the SampleServer service" +else: + addr = sys.argv[1] + print "Searching for SampleServer on %s" % addr + +# search for the SampleServer service +uuid = "94f39d29-7d6d-437d-973b-fba39e49d4ee" +service_matches = find_service( uuid = uuid, address = addr ) + +if len(service_matches) == 0: + print "couldn't find the SampleServer service =(" + sys.exit(0) + +first_match = service_matches[0] +port = first_match["port"] +name = first_match["name"] +host = first_match["host"] + +print "connecting to \"%s\" on %s" % (name, host) + +# Create the client socket +sock=BluetoothSocket( RFCOMM ) +sock.connect((host, port)) + +print "connected. type stuff" +while True: + data = raw_input() + if len(data) == 0: break + sock.send(data) + +sock.close() |
