Merge "Update serial console example client for py3"
This commit is contained in:
@@ -54,7 +54,11 @@ A simple client for *test purpose* can be written with few lines of Python.
|
|||||||
while not self.terminated:
|
while not self.terminated:
|
||||||
try:
|
try:
|
||||||
b = self.sock.recv(4096)
|
b = self.sock.recv(4096)
|
||||||
sys.stdout.write(b)
|
while len(b) > 0:
|
||||||
|
# websocket data: opcode + length + data
|
||||||
|
word = b[2:b[1]+2]
|
||||||
|
b = b[b[1]+2:]
|
||||||
|
sys.stdout.buffer.write(word)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
except: # socket error expected
|
except: # socket error expected
|
||||||
pass
|
pass
|
||||||
@@ -62,8 +66,8 @@ A simple client for *test purpose* can be written with few lines of Python.
|
|||||||
self.terminate()
|
self.terminate()
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if len(sys.argv) != 2 or not sys.argv[1].startswith("ws"):
|
if len(sys.argv) != 2 or not sys.argv[1].startswith("ws"):
|
||||||
print "Usage %s: Please use websocket url"
|
print("Usage %s: Please use websocket url")
|
||||||
print "Example: ws://127.0.0.1:6083/?token=xxx"
|
print("Example: ws://127.0.0.1:6083/?token=xxx")
|
||||||
exit(1)
|
exit(1)
|
||||||
try:
|
try:
|
||||||
ws = LazyClient(sys.argv[1], protocols=['binary'])
|
ws = LazyClient(sys.argv[1], protocols=['binary'])
|
||||||
@@ -72,7 +76,7 @@ A simple client for *test purpose* can be written with few lines of Python.
|
|||||||
# keyboard event...
|
# keyboard event...
|
||||||
c = sys.stdin.read(1)
|
c = sys.stdin.read(1)
|
||||||
if c:
|
if c:
|
||||||
ws.send(c)
|
ws.send(c.encode('utf-8'), binary=True)
|
||||||
ws.run_forever()
|
ws.run_forever()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
ws.close()
|
ws.close()
|
||||||
|
Reference in New Issue
Block a user