<s> from calvin . runtime . south . plugins . async import server_connection <EOL> class MessageServer ( object ) : <EOL> def __init__ ( self , node , actor_id ) : <EOL> super ( MessageServer , self ) . __init__ ( ) <EOL> self . _trigger = node . sched . trigger_loop <EOL> self . _listener = server_connection . UDPServerProtocol ( self . trigger , actor_id ) <EOL> def trigger ( self , actor_ids ) : <EOL> self . _trigger ( actor_ids = actor_ids ) <EOL> def have_data ( self ) : <EOL> return self . _listener . have_data ( ) <EOL> def data_get ( self ) : <EOL> return self . _listener . data_get ( ) <EOL> def start ( self , host , port ) : <EOL> self . _listener . start ( host , port ) <EOL> def stop ( self ) : <EOL> self . _listener . stop ( ) <EOL> class Server ( object ) : <EOL> def __init__ ( self , node , mode , delimiter , max_length , actor_id = None ) : <EOL> super ( Server , self ) . __init__ ( ) <EOL> self . connection_factory = server_connection . ServerProtocolFactory ( node . sched . trigger_loop , mode , <EOL> delimiter , max_length , actor_id ) <EOL> def start ( self , host , port ) : <EOL> self . connection_factory . start ( host , port ) <EOL> def stop ( self ) : <EOL> self . connection_factory . stop ( ) <EOL> def accept ( self ) : <EOL> return self . connection_factory . accept ( ) <EOL> def connection_pending ( self ) : <EOL> if self . connection_factory . pending_connections : <EOL> return True <EOL> return False <EOL> def send ( self , connection , data ) : <EOL> connection . send ( data ) <EOL> def receive ( self , connection ) : <EOL> return connection . data_get ( ) <EOL> class ServerHandler ( object ) : <EOL> def __init__ ( self , node , actor ) : <EOL> super ( ServerHandler , self ) . __init__ ( ) <EOL> self . node = node <EOL> self . server = None <EOL> self . _actor = actor <EOL> def start ( self , host , port , mode , delimiter = None , max_length = None ) : <EOL> if mode == "<STR_LIT>" : <EOL> self . server = MessageServer ( self . node , actor_id = self . _actor . id ) <EOL> else : <EOL> self . server = Server ( self . node , mode , delimiter , max_length , actor_id = self . _actor . id ) <EOL> self . server . start ( host , port ) <EOL> return self . server <EOL> def stop ( self ) : <EOL> self . server . stop ( ) <EOL> def register ( node , actor ) : <EOL> """<STR_LIT>""" <EOL> return ServerHandler ( node , actor ) </s>
