Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ymgve
Created December 24, 2016 02:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ymgve/b372d703d5325b1f4977fbed93d499df to your computer and use it in GitHub Desktop.
Save ymgve/b372d703d5325b1f4977fbed93d499df to your computer and use it in GitHub Desktop.
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