Question

In: Computer Science

How to use Bluetooth to exchange Data between 2 computers. Develop a program with Python to...

How to use Bluetooth to exchange Data between 2 computers. Develop a program with Python to demonstrate this data exchange.

Solutions

Expert Solution

"""
Python script to send messages to a sever over Bluetooth
using PyBluez (with Python 2).

This is how we send data to other person over bluteooth
"""

import bluetooth # importing PyBlueZ

serverMACAddress = '00:1f:e1:dd:08:3d' #Mac Address of the server
port = 3 # Port number through which the data is transferred
s = bluetooth.BluetoothSocket(bluetooth.RFCOMM) #create a connection
s.connect((serverMACAddress, port)) #connect to the Mac Address through port

#looping infinite times until a quit command is received
while 1:
text = raw_input() # Note change to the old (Python 2) raw_input
if text == "quit":
break
s.send(text)
sock.close() # closing the connection

"""
Python script to receive messages from a client over
Bluetooth using PyBluez (with Python 2).

This is how we recieve messages over bluetooth connection
"""

import bluetooth

hostMACAddress = '00:1f:e1:dd:08:3d' # The MAC address of a Bluetooth adapter on the server. The server might have multiple Bluetooth adapters.
port = 3
backlog = 1
size = 1024
s = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
s.bind((hostMACAddress, port))
s.listen(backlog)
try:
client, clientInfo = s.accept()
while 1:
data = client.recv(size)
if data:
print(data)
client.send(data) # Echo back to client
except:  
print("Closing socket")
client.close()
s.close()


Related Solutions

Develop a program using python to demonstrate data exchange using USB protocol.
Develop a program using python to demonstrate data exchange using USB protocol.
The Objectives are to: Use IDLE IDE for Python. Develop a few simple Python programs and...
The Objectives are to: Use IDLE IDE for Python. Develop a few simple Python programs and show they will translate and run. Experience error messages when you enter bad syntax the interpreter cannot understand. Discussion: The best way to learn Python (or any programming language) is to write & run Python programs. In this lab you will enter two programs, and run them to produce the output. Then deliberately insert syntax errors to see what kinds of error messages you...
Use Python: Develop neurons and print truth table of the following 2-input logic gates: AND, OR,...
Use Python: Develop neurons and print truth table of the following 2-input logic gates: AND, OR, NAND, NOR, XOR, XNOR and 1-input NOT gate (Notice: use Markdown to explain how you developed a neuron, and to insert images showing the truth table of logic gates before coding)
Python Exercise 2 A program is to display all odd numbers between 10 and 3000. The...
Python Exercise 2 A program is to display all odd numbers between 10 and 3000. The starting value and end value are to be assigned by the programmer, not requested from user.
TheMathGame Develop a program in PYTHON that will teach children the basic math facts of addition....
TheMathGame Develop a program in PYTHON that will teach children the basic math facts of addition. The program generates random math problems for students to answer. User statistics need to be kept in RAM as the user is playing the game and recorded in a text file so that they may be loaded back into the program when the student returns to play the game again. In addition, the youngster should be allowed to see how (s)he is doing at...
Develop a python program to create a quiz with limited time and attempts!!! Add comments and...
Develop a python program to create a quiz with limited time and attempts!!! Add comments and screenshot of running the program quiz could be of anything like , what's the sum of 2&2. There should be number of attempts(limited) suppose if the answer is wrong.
This program is in Python ### simulates packets of data arriving at irregular times. The data...
This program is in Python ### simulates packets of data arriving at irregular times. The data gets ### read from the file and then you must place it in a queue where it will wait ### its turn to get processed. The "processing" happens in a threaded subroutine ### called "process_input_data". That function should pull data from the queue, ### hash the student ID number, and then store the data in a hash table which ### you have to implement....
This program should be done in python. This must use the principles of object oriented program....
This program should be done in python. This must use the principles of object oriented program. Create one or more classes to play Four-in-a-Row (also called Connect Four) with a user. It’s similar to tic-tac-toe but the board is of size 7×6 and discs fall straight through so the legal moves are more stringent than tic-tac-toe. The state of the board should be printed to the terminal after each legal move. You can represent the different colored discs as X’s...
Develop a python program that prompts the user to take up the quiz (which has choices)...
Develop a python program that prompts the user to take up the quiz (which has choices) with limited attempts and limited time. Suppose if the user answered wrong then they have to get numer of attempts(limited) Quiz should have questions on General knowldge & multiple choices for those questions
C++ Create a program that use the linkedbag 3. Develop a program to maintain a list...
C++ Create a program that use the linkedbag 3. Develop a program to maintain a list of homework assignments. When an assignment is assigned, add it to the list, and when it is completed, remove it. You should keep track of the due date. Your program should provide the following services: • Add a new assignment. • Remove an assignment. • Provide a list of the assignments in the order they were assigned. • Find the assignment(s) with the earliest...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT