From 9ec97d86351171a79ddb99a5c70caef8d68143a5 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Fri, 2 Apr 2010 19:16:25 -0500 Subject: [PATCH] Base64 encode/decode for client Javascript. --- wsproxy.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/wsproxy.py b/wsproxy.py index b6c90e77..9e0f2f31 100755 --- a/wsproxy.py +++ b/wsproxy.py @@ -1,6 +1,7 @@ #!/usr/bin/python import sys, os, socket, time, traceback +from base64 import b64encode, b64decode from select import select server_handshake = """HTTP/1.1 101 Web Socket Protocol Handshake\r @@ -36,29 +37,28 @@ def proxy(client, target): if client in ins: buf = client.recv(1024) if len(buf) == 0: raise Exception("Client closed") - tqueue.append(buf[1:-1]) - #print "Client recv: %s (%d)" % (buf[1:-1], len(buf)) - traffic("}") + tqueue.append(b64decode(buf[1:-1])) + print "Client recv: %s (%d)" % (repr(buf[1:-1]), len(buf)) + #traffic("}") if target in ins: buf = target.recv(1024) if len(buf) == 0: raise Exception("Target closed") - cqueue.append("\x00" + buf + "\xff") - #print "Target recv: %s (%d)" % (buf, len(buf)) - traffic("{") + cqueue.append("\x00" + b64encode(buf) + "\xff") + print "Target recv: %s (%d)" % (repr(buf), len(buf)) + #traffic("{") if cqueue and client in outs: while cqueue: - #print "Client send: %s" % cqueue[0] + print "Client send: %s" % repr(cqueue[0]) client.send(cqueue.pop(0)) - traffic("<") + #traffic("<") if tqueue and target in outs: while tqueue: - #print "Target send: %s" % tqueue[0] - sys.stdout.flush() + print "Target send: %s" % repr(tqueue[0]) target.send(tqueue.pop(0)) - traffic(">") + #traffic(">") def start_server(listen_port, target_host, target_port): lsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)