EchoHandler and control channel handling

develop
Sven Slootweg 13 years ago
parent 1ffb62790a
commit 636a82c80b

@ -31,7 +31,7 @@ class Client:
def __init__(self, connstream): def __init__(self, connstream):
self.stream = connstream self.stream = connstream
self.channel_map[0] = Channel() self.channel_map[0] = Channel(EchoHandler())
def process_data(self, data): def process_data(self, data):
self.buff += data self.buff += data
@ -49,9 +49,9 @@ class Client:
channel_numeric = to_numeric(channel_identifier) channel_numeric = to_numeric(channel_identifier)
if channel_numeric in self.channel_map: if channel_numeric in self.channel_map:
print "Received data on channel %d: %s" % (channel_numeric, data) self.channel_map[channel_numeric].process_chunk(data)
else: else:
print "Received data on NON-EXISTENT channel %d" % channel_numeric print "WARNING: Received data on non-existent channel %d" % channel_numeric
class Channel: class Channel:
numeric = 0 numeric = 0
@ -66,9 +66,13 @@ class Channel:
self.handler.process(chunk) self.handler.process(chunk)
class Handler: class Handler:
def process(chunk): def process(self, chunk):
pass pass
class EchoHandler(Handler):
def process(self, chunk):
print "Received %s" % chunk
bindsocket = socket.socket() bindsocket = socket.socket()
bindsocket.bind(('0.0.0.0', 9151)) bindsocket.bind(('0.0.0.0', 9151))
bindsocket.listen(5) bindsocket.listen(5)

@ -22,6 +22,6 @@ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ssl_sock = ssl.wrap_socket(s, cert_reqs=ssl.CERT_REQUIRED, ca_certs=allowed_certs) ssl_sock = ssl.wrap_socket(s, cert_reqs=ssl.CERT_REQUIRED, ca_certs=allowed_certs)
ssl_sock.connect(('localhost', 9151)) ssl_sock.connect(('localhost', 9151))
ssl_sock.write(to_identifier(3) + 'test data' + EOC + to_identifier(4190) + 'SAMPLEDATA' + EOC) ssl_sock.write(to_identifier(0) + 'test data' + EOC + to_identifier(4190) + 'SAMPLEDATA' + EOC)
ssl_sock.close() ssl_sock.close()

Loading…
Cancel
Save