Started Client-Server based on ECS and ZeroMQ

This commit is contained in:
Swann
2019-01-25 14:40:31 +01:00
parent ef120e8d3c
commit 3f9aaf37b3
3 changed files with 85 additions and 13 deletions

30
net_systems.py Normal file
View File

@ -0,0 +1,30 @@
import time
import zmq
import net_components
from libs.esper import esper
class NetworkSystem(esper.Processor):
"""
Handle Client-Server session managment
"""
def __init__(self):
super().__init__()
def process(self):
# This will iterate over every Entity that has BOTH of these components:
for ent, session in self.world.get_component(net_components.Session):
# Wait for next request from client
message = session.socket.recv()
print("Received request: %s" % message)
# Do some 'work'
time.sleep(1)
# Send reply back to client
session.socket.send(b"World")