📄 059-btclient.py
字号:
import appuifw, socket, e32ECHO = Truedef choose_service(services): names = [] channels = [] for name, channel in services.items(): names.append(name) channels.append(channel) index = appuifw.popup_menu(names, u"Choose service") return channels[index]def read_and_echo(fd): buf = r = "" while r != "\n" and r != "\r": r = fd.read(1) if ECHO: fd.write(r) buf += r if ECHO: fd.write("\n") return bufaddress, services = socket.bt_discover()channel = choose_service(services)conn = socket.socket(socket.AF_BT, socket.SOCK_STREAM)conn.connect((address, channel))to_peer = conn.makefile("rw", 0)while True: msg = appuifw.query(u"Send a message", "text") if msg: print >> to_peer, msg + "\r" print "Sending: " + msg print "Waiting for reply..." reply = read_and_echo(to_peer).strip() appuifw.note(unicode(reply), "info") if reply.find("bye!") != -1: break else: breakto_peer.close()conn.close()print "bye!"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -