Python
  Home arrow Python arrow Page 4 - 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? 
Google.com  
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 the Client
    ( Page 4 of 5 )

    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
     

       

    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 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek