Last active
March 23, 2021 18:42
-
-
Save kevindoran/5428390 to your computer and use it in GitHub Desktop.
A simple Python script to receive messages from a client over Bluetooth using Python sockets (with Python 3.3 or above).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A simple Python script to receive messages from a client over | |
Bluetooth using Python sockets (with Python 3.3 or above). | |
""" | |
import socket | |
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 # 3 is an arbitrary choice. However, it must match the port used by the client. | |
backlog = 1 | |
size = 1024 | |
s = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM) | |
s.bind((hostMACAddress,port)) | |
s.listen(backlog) | |
try: | |
client, address = s.accept() | |
while 1: | |
data = client.recv(size) | |
if data: | |
print(data) | |
client.send(data) | |
except: | |
print("Closing socket") | |
client.close() | |
s.close() |
Hi, maxcoldson and mitjad,
Well, people say there is the same available for python3.9. I don't know about it. But you can check.
I can definately tell you from doing it myself that python 3.9 is the solution.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, maxcoldson and mitjad,
Well, people say there is the same available for python3.9. I don't know about it. But you can check.