Home arrow Python arrow Page 4 - Bluetooth Programming in Python: Network Programming using RFCOMM

Developing the Client - Python

In the last article I discussed various Bluetooth profiles. If one wants to create a client-server based application using Bluetooth, then one should program for the RFCOMM profile. RFCOMM offers a socket-based client-server paradigm for providing services.

TABLE OF CONTENTS:
  1. Bluetooth Programming in Python: Network Programming using RFCOMM
  2. Developing Applications for RFCOMM, Step by Step
  3. Listening for requests
  4. Developing the Client
  5. RFCOMM in the Real World
By: A.P.Rajshekhar
Rating: starstarstarstarstar / 10
December 12, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

The steps necessary to developing the client are almost the same as those we needed to take to develop the server. The steps are

  1. Create a socket
  2. Connect to a device
  3. Sending/receiving data

The first and third steps are same as that of creating the server. So only the second step needs scrutinizing. I explain the details below.

Create a socket

Just as with a server socket, to create a client socket the BluetoothSocket() method needs to be called with RFCOMM as the protocol. So, to create a socket that would connect to a server, the statement will be

client_socket= Bluetooth.BluetoothSocket(Bluetooth.RFCOMM)


Connect to a device

To connect to a server, the client needs to know the address of the server. With Bluetooth, the address will be the address of the device, which is of the form "XX:XX:XX:XX:XX". So, to connect to a server running on a device with an address of "01:23:45:67:89:AB",  the connect() method needs to be called on the socket object with the port number and address of the server. For example, if the server port number is 4000 and the address is "01:23:45:67:89:AB", then the statement to connect to it is 

address="01:23:45:67:89:AB"

port=4000

client_sock.connect((address, port))


Sending/receiving data

At the client side too, the way to send and /or receive data is the same as that at the server side. So, to receive any data from the server, the statement would be

data = client_sockect.recv(1024)

print "received [%s]" % data


That completes the steps necessary to create a client and a server. Next, let us see how to develop a server that transfers a file using Bluetooth and RFCOMM.



 
 
>>> More Python Articles          >>> More By A.P.Rajshekhar
 

blog comments powered by Disqus
   

PYTHON ARTICLES

- Python Big Data Company Gets DARPA Funding
- Python 32 Now Available
- Final Alpha for Python 3.2 is Released
- Python 3.1: String Formatting
- Python 3.1: Strings and Quotes
- Python 3.1: Programming Basics and Strings
- Tuples and Other Python Object Types
- The Dictionary Python Object Type
- String and List Python Object Types
- Introducing Python Object Types
- Mobile Programming using PyS60: Advanced UI ...
- Nested Functions in Python
- Python Parameters, Functions and Arguments
- Python Statements and Functions
- Statements and Iterators in Python

Developer Shed Affiliates

 



© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap

Dev Shed Tutorial Topics: