Skip to content

Instantly share code, notes, and snippets.

@kevindoran
Last active November 6, 2022 23:39
Show Gist options
  • Save kevindoran/5428612 to your computer and use it in GitHub Desktop.
Save kevindoran/5428612 to your computer and use it in GitHub Desktop.
A simple Python script to receive messages from a client over Bluetooth using PyBluez (with Python 2).
"""
A simple Python script to receive messages from a client over
Bluetooth using PyBluez (with Python 2).
"""
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()
@datend3nker
Copy link

I have the problem when I send a file with the size 12kb only 1kb is being received even when i set the buffer limit much above

@linoqui14
Copy link

You need to make an array of bytes and send it by 1kb then merge it on the receiver

@linoqui14
Copy link

@detend3nKer you should post in on StackOverflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment