【发布时间】:2017-11-06 19:13:09
【问题描述】:
我在 Python 3 上创建了简单的蓝牙 RFCOMM 服务器
这是我的代码:
import bluetooth
class Bluetooth:
def __init__(self, port, backlog, size):
#backlog = number of users who can connect to socket at the same time
#size = message size
s = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
s.bind(("", port)) #(mac addres, port)
s.listen(backlog)
print("Server is active, waiting for connection!")
while True:
client, clientInfo = s.accept()
print("Connected with :", clientInfo)
try:
while True:
data = client.recv(size)
if data:
print(data)
except:
print("Closing socket")
client.close()
print("Waiting for connection!")
s.close()
print("Server closed!")
当我从 BlueTerm、BlueTerm2、蓝牙终端 (...) 等 Android 设备应用程序发送数据时,我会收到来自 PyCharm 的 b'my string' 屏幕截图
我的文本数据前面的b 符号是什么意思?
如何只打印我的字符串?
【问题讨论】:
标签: python string bluetooth server rfcomm