Python
  Home arrow Python arrow Page 3 - 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 - Listening for requests
    ( Page 3 of 5 )

    Once a socket has been bound to a port, the next step is to make it listen for incoming requests. To do this, the listen() method needs to be called on the socket object. The listen() method accepts the number of requests to be kept in queue as the argument. For example, to make a socket start listening with a queue of size 3, the statement will be 

    server_socket.listen(3)


    Accepting the requests

    Once a request is received, it has to be accepted so that communication can start. To do so, one has to call the accept() method on the socket object. The accept() method doesn't have any arguments. It returns a tuple containing the address of the client and socket object through which further communication can be accomplished. So the statement to accept a connection is

    client_socket,address=server_socket.accept()


    Sending/receiving data

    The last step is sending and/or receiving data. If the server is on a normal PC, then sending and receiving can be done using the Python library. However, if the server is on a smart phone, for example, then the library required will be based on the OS of the smart phone. For a normal PC, one would have to call send() and recv() methods on the socket object returned by the accept() method. Both accept strings as arguments. For example, if the server wants to send a message, say, "hello", the code will be

    client_socket.send("Hello from server")

    That completes the server part. Next comes the client.



     
     
    >>> 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 3 Hosted by Hostway
    Stay green...Green IT