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

Listening for requests - 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

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
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

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

 


Dev Shed Tutorial Topics: