Created
December 24, 2016 02:30
-
-
Save ymgve/b372d703d5325b1f4977fbed93d499df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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