Skip to content

Instantly share code, notes, and snippets.

@thatfunkymunki
Created March 6, 2016 00:59
Show Gist options
  • Save thatfunkymunki/3a4fc78c97dd4e3d4c86 to your computer and use it in GitHub Desktop.
Save thatfunkymunki/3a4fc78c97dd4e3d4c86 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import json
from websocket import create_connection
import websocket
MYSQL_SPECIAL_CHARS= [
("\\","\\\\"),
("\0","\\0"),
("\n","\\n"),
("\r","\\r"),
("'","\\'"),
('"','\\"'),
("\x1a","\\Z"),
]
def mysql_escape(s):
for find, replace in MYSQL_SPECIAL_CHARS:
s = s.replace(find, replace)
return s
#
#for i in range(0,65535):
# char_i= unichr(i)
# escaped = mysql_escape(char_i)
# if( char_i != escaped ):
# print( "found difference %d is %s and %s " % (i,char_i, escaped))
# s = raw_input( "any key to continue" )
#
server = "ws://52.86.232.163:32800/ws"
ws = create_connection(server)
print "connected to host %s" % server
while True:
try:
msg = ws.recv()
print "Received %s" % msg
#query = "{\"type\":\"get_answer\",\"question\":\"name\",\"answer\":\"as\x00\x5c\\""}"
query = "{\"type\":\"get_answer\",\"question\":\"name\",\"answer\": [92,0]}"
# test = json.loads(query)
# print ("json loaded %s from %s" % (query, test))
ws.send(query)
print("sent %s" % query)
s = raw_input(" any key to continue ")
except websocket.WebSocketConnectionClosedException:
print("socket was disconnected, reconnecting")
ws = create_connection(server)
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment