Skip to content
Snippets Groups Projects
Commit ffb76bf0 authored by KERDREUX Jerome's avatar KERDREUX Jerome
Browse files

Cleanup

parent 8381cc87
Branches
No related tags found
No related merge requests found
......@@ -5,8 +5,9 @@ import struct
from xaal.lib import MessageFactory, config, helpers
ADDR = '224.0.29.200'
PORT = 1236
ADDR = config.address
PORT = config.port
class EchoServerProtocol(asyncio.Protocol):
def __init__(self, on_con_lost):
......@@ -36,25 +37,25 @@ class EchoServerProtocol(asyncio.Protocol):
def datagram_received(self, data, addr):
# print('Received %r from %s' % (data, addr))
msg = self.mf.decode_msg(data)
if msg:
msg.dump()
def connection_lost(self, exc):
print(f"Connexion lost {exc}")
async def main():
loop = asyncio.get_running_loop()
print("Starting UDP server")
on_con_lost = loop.create_future()
transport, protocol = await loop.create_datagram_endpoint( lambda: EchoServerProtocol(on_con_lost), local_addr=(ADDR, PORT),reuse_port=True)
transport, protocol = await loop.create_datagram_endpoint(
lambda: EchoServerProtocol(on_con_lost), local_addr=(ADDR, PORT), reuse_port=True
)
try:
await asyncio.sleep(3600) # Serve for 1 hour.
finally:
transport.close()
try:
asyncio.run(main())
except KeyboardInterrupt:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment