pyssb/examples/test_server.py

38 lines
911 B
Python
Raw Normal View History

2017-07-31 21:17:59 +00:00
import logging
from asyncio import get_event_loop, ensure_future
2017-05-25 10:47:01 +00:00
2017-07-31 21:17:59 +00:00
from colorlog import ColoredFormatter
2017-05-25 10:47:01 +00:00
from ssb.packet_stream import PSServer
2017-08-05 10:24:46 +00:00
from ssb.util import load_ssb_secret
2017-05-25 10:47:01 +00:00
2017-07-31 21:17:59 +00:00
async def on_connect():
2017-08-01 17:32:36 +00:00
ensure_future(packet_stream, loop=loop)
2017-07-31 21:17:59 +00:00
# create console handler and set level to debug
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
# create formatter
formatter = ColoredFormatter('%(log_color)s%(levelname)s%(reset)s:%(bold_white)s%(name)s%(reset)s - '
'%(cyan)s%(message)s%(reset)s')
# add formatter to ch
ch.setFormatter(formatter)
# add ch to logger
logger = logging.getLogger('packet_stream')
logger.setLevel(logging.DEBUG)
logger.addHandler(ch)
2017-05-25 10:47:01 +00:00
loop = get_event_loop()
2017-05-25 10:47:01 +00:00
2017-08-05 10:24:46 +00:00
packet_stream = PSServer('127.0.0.1', 8008, load_ssb_secret()['keypair'], loop=loop)
2017-05-25 10:47:01 +00:00
packet_stream.on_connect(on_connect)
packet_stream.listen()
2017-05-25 10:47:01 +00:00
loop.run_forever()
loop.close()