Files
multi-user/net_systems.py

40 lines
1.1 KiB
Python
Raw Normal View History

import time
import zmq
2019-01-25 17:02:04 +01:00
import net_components
from libs.esper import esper
class NetworkSystem(esper.Processor):
"""
Handle Client-Server session managment
"""
def __init__(self):
super().__init__()
2019-01-25 17:28:53 +01:00
# Initialize poll set
2019-01-25 17:07:45 +01:00
# TODO: Use zmq_poll..
def process(self):
# This will iterate over every Entity that has BOTH of these components:
2019-01-25 17:02:04 +01:00
for ent, (net_interface, user) in self.world.get_components(net_components.NetworkInterface,net_components.User):
if user.role is net_components.Role.CLIENT:
net_interface.socket.send(b"Waiting server response")
2019-01-25 17:02:04 +01:00
if user.role is net_components.Role.SERVER:
2019-01-25 17:28:53 +01:00
print("Server loops")
try:
socks = dict(net_interface.poller.poll())
print("test")
except KeyboardInterrupt:
break
if net_interface.socket in socks:
message = net_interface.socket.recv()
print("test")
# process task