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)
Develop a python program to - Create a 2D 10x10 numpy array and fill it with...
Develop a python program to - Create a 2D 10x10 numpy array and fill it with the random numbers between 1 and 9 (including 0 and 9). - Assume that you are located at (0,0) (upper-left corner) and want to move to (9,9) (lower-right corner) step by step. In each step, you can only move right or down in the array. - Develop a function to simulate random movement from (0,0) to (9,9) and return sum of all cell values...
You are asking to develop a “Triangle Guessing” game in Python for the assignment. The program...
You are asking to develop a “Triangle Guessing” game in Python for the assignment. The program accepts the lengths of three (3) sides of a triangle as input from a player. The program output should indicate whether the triangle is a right triangle, an acute triangle, or an obtuse triangle. 1.Tips to help you for this assignment: Make sure each side of the triangle is a positive integer. Use try/except for none positive integer input. 2. Validating the triangle. That...
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.
Develop a python program that will determine if a department store customer has exceeded the credit...
Develop a python program that will determine if a department store customer has exceeded the credit limit on a charge account. For each customer, the following facts are available:  Account number  Balance at the beginning of the month  Total of all items charged by this customer this month  Total of all credits applied to this customer’s account this month  Allowed credit limit The program should input each of the facts, calculate the new balance (=beginning...
Develop a python program that will determine if a department store customer has exceeded the credit...
Develop a python program that will determine if a department store customer has exceeded the credit limit on a charge account. For each customer, the following facts are available:  Account number, Balance at the beginning of the month, Total of all items charged by this customer this month, Total of all credits applied to this customer’s account this month and Allowed credit limit. The program should input each of the facts, calculate the new balance (=beginning balance + charges – credits),...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT