059-btclient.py
来自「this code is used for edit on os of s60」· Python 代码 · 共 45 行
PY
45 行
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 + =
减小字号Ctrl + -
显示快捷键?