Python
  Home arrow Python arrow Page 2 - Bluetooth Programming in Python: Network Programming using RFCOMM
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PYTHON

Bluetooth Programming in Python: Network Programming using RFCOMM
By: A.P.Rajshekhar
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 10
    2007-12-12


    Table of Contents:
  • Bluetooth Programming in Python: Network Programming using RFCOMM
  • Developing Applications for RFCOMM, Step by Step
  • Listening for requests
  • Developing the Client
  • RFCOMM in the Real World

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Bluetooth Programming in Python: Network Programming using RFCOMM - Developing Applications for RFCOMM, Step by Step
    ( Page 2 of 5 )

    The steps necessary to develop RFCOMM-based applications can be divided into two main sets. They are creating the server and creating the client. Each of the steps can be again divided into sub-steps. Let us take each step one at a time.

    Creating the Server

    RFCOMM applications are essentially Bluetooth-based services. This has to be kept in mind when developing the server. The importance of this point will become clear in the steps regarding the client. Creating the server can be further divided into following steps:

    1. Creating the Server Socket
    2. Binding to a port
    3. Listening for requests
    4. Accepting the requests
    5. Sending data

    The steps are same as that for creating a TCP/IP-based server. However, the first and last step differs for RFCOMM. The details are as follows.

    Creating the Server Socket

    The first step is to create the socket that will listen for and accept incoming requests and create the connection. The sockets one would use when working with RFCOMM are Bluetooth sockets. To create a Bluetooth socket, BluetoothSocket needs to be called with the protocol to be used. In this case the protocol is RFCOMM. So, to create a socket named server_socket the statement will be:

    server_socket= Bluetooth.BluetoothSocket(Bluetooth.RFCOMM)


    This statement only creates a simple Bluetooth-based socket that uses RFCOMM for communication. The next three steps make it a server socket.

    Binding to a Port

    This is the second step to making a simple socket work as a server socket. The socket object needs to be bound to an address and a port so that it can start listening for requests. However, since the socket will be communicating over Bluetooth, an IP address is not required. PyBluez will use the address of the device on which it is running. If the device is a desktop PC, then the address will correspond to the address provided by the Bluetooth adapter or dongle.

    To bind a socket object to a port, the bind() method needs to be called on the socket object. The argument passed is a tuple containing the address and the port number with which the socket has to be bound. For example, to bind a socket to a port, say 11, the statement will be

    server_socket.bind(("",11)) 

    One point to keep in mind while working with RFCOMM is that RFCOMM uses ports between 1-30 only.



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

       

    PYTHON ARTICLES

    - 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
    - Sequences and Sets in Python
    - Python Expressions and Operators
    - Dictionaries, Variables and Statements in Py...
    - Data Types in Python
    - The Python Language
    - SSH with Twisted





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    Stay green...Green IT