Working with Raw rectangles and capital letter keys.

This commit is contained in:
Joel Martin
2010-04-05 23:54:30 -05:00
parent c8460b0310
commit 64ab5c4ded
5 changed files with 314 additions and 239 deletions

View File

@@ -4,6 +4,8 @@ import sys, os, socket, time, traceback
from base64 import b64encode, b64decode
from select import select
buffer_size = 65536
server_handshake = """HTTP/1.1 101 Web Socket Protocol Handshake\r
Upgrade: WebSocket\r
Connection: Upgrade\r
@@ -35,30 +37,30 @@ def proxy(client, target):
if excepts: raise Exception("Socket exception")
if client in ins:
buf = client.recv(1024)
buf = client.recv(buffer_size)
if len(buf) == 0: raise Exception("Client closed")
tqueue.append(b64decode(buf[1:-1]))
print "Client recv: %s (%d)" % (repr(buf[1:-1]), len(buf))
#traffic("}")
#print "Client recv: %s (%d)" % (repr(buf[1:-1]), len(buf))
traffic("}")
if target in ins:
buf = target.recv(1024)
buf = target.recv(buffer_size)
if len(buf) == 0: raise Exception("Target closed")
cqueue.append("\x00" + b64encode(buf) + "\xff")
print "Target recv: %s (%d)" % (repr(buf), len(buf))
#traffic("{")
#print "Target recv: %s (%d)" % (repr(buf), len(buf))
traffic("{")
if cqueue and client in outs:
while cqueue:
print "Client send: %s" % repr(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" % repr(tqueue[0])
#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)