update tests
This commit is contained in:
@ -1,12 +1,14 @@
|
||||
import time
|
||||
import asyncio
|
||||
|
||||
import zmq
|
||||
import zmq.asyncio
|
||||
|
||||
import net_components
|
||||
from libs.esper import esper
|
||||
|
||||
|
||||
class NetworkSystem(esper.Processor):
|
||||
class SessionSystem(esper.Processor):
|
||||
"""
|
||||
Handle Client-Server session managment
|
||||
"""
|
||||
@ -20,21 +22,24 @@ class NetworkSystem(esper.Processor):
|
||||
def process(self):
|
||||
# This will iterate over every Entity that has BOTH of these components:
|
||||
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")
|
||||
|
||||
if user.role is net_components.Role.SERVER:
|
||||
print("Server loops")
|
||||
try:
|
||||
socks = dict(net_interface.poller.poll())
|
||||
message = net_interface.socket.recv()
|
||||
print("test")
|
||||
except KeyboardInterrupt:
|
||||
break
|
||||
if net_interface.socket in socks:
|
||||
message = net_interface.socket.recv()
|
||||
break
|
||||
|
||||
print("test")
|
||||
# process task
|
||||
|
||||
|
||||
|
||||
if user.role is net_components.Role.CLIENT:
|
||||
# Send reply back to client
|
||||
socket.send(b"Hello")
|
||||
|
||||
@asyncio.coroutine
|
||||
def recv_and_process():
|
||||
sock = ctx.socket(zmq.PULL)
|
||||
sock.bind(url)
|
||||
msg = yield from sock.recv_multipart() # waits for msg to be ready
|
||||
reply = yield from async_process(msg)
|
||||
yield from sock.send_multipart(reply)
|
||||
|
Reference in New Issue
Block a user