Sending data back

develop
Sven Slootweg 13 years ago
parent 636a82c80b
commit e8afe3e404

@ -9,6 +9,8 @@ key_path = '/home/sven/ssl/private'
# Configuration ends here
################################
EOC = "\0"
import socket, ssl, select, math
def remove_from_list(ls, val):
@ -31,11 +33,11 @@ class Client:
def __init__(self, connstream):
self.stream = connstream
self.channel_map[0] = Channel(EchoHandler())
self.channel_map[0] = Channel(self, EchoHandler())
def process_data(self, data):
self.buff += data
stack = self.buff.split("\0")
stack = self.buff.split(EOC)
self.buff = stack.pop()
for chunk in stack:
@ -57,14 +59,20 @@ class Channel:
numeric = 0
binary = False
handler = None
client = None
def __init__(self, handler, binary=False):
def __init__(self, client, handler, binary=False):
self.handler = handler
self.binary = binary
self.client = client
def process_chunk(self, chunk):
self.send("ohai")
self.handler.process(chunk)
def send(self, data):
self.client.stream.send(to_identifier(self.numeric) + data + EOC)
class Handler:
def process(self, chunk):
pass

@ -24,4 +24,6 @@ ssl_sock.connect(('localhost', 9151))
ssl_sock.write(to_identifier(0) + 'test data' + EOC + to_identifier(4190) + 'SAMPLEDATA' + EOC)
print ssl_sock.read()[2:]
ssl_sock.close()

Loading…
Cancel
Save