Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import websocket, random
def encode_unicode(n):
s = ""
if n <= 0x7f:
s = chr(n)
elif n <= 0x7ff:
s = chr(0xc0 | ((n & 0x7c0) >> 6)) + chr(0x80 | ((n & 0x3f) >> 0))
elif n <= 0xffff:
s = chr(0xe0 | ((n & 0xf000) >> 12)) + chr(0x80 | ((n & 0xfc0) >> 6)) + chr(0x80 | ((n & 0x3f) >> 0))
elif n <= 0x1fffff:
s = chr(0xf0 | ((n & 0x1c0000) >> 18)) + chr(0x80 | ((n & 0x3f000) >> 12)) + chr(0x80 | ((n & 0xfc0) >> 6)) + chr(0x80 | ((n & 0x3f) >> 0))
return s
ws = websocket.WebSocket()
ws.connect("ws://192.241.176.246:8888/")
ws.send("\x00" * 8)
res = ws.recv()
print repr(res)
s = ""
for a in res.split("|")[:-1]:
a = int(a)
s += encode_unicode(a)
ws.send(s)
while True:
res = ws.recv()
print repr(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment