<s> import eventlet <EOL> import sys <EOL> from eventlet . green import socket , zmq <EOL> from eventlet . hubs import use_hub <EOL> use_hub ( '<STR_LIT>' ) <EOL> ADDR = '<STR_LIT>' <EOL> ctx = zmq . Context ( ) <EOL> def publish ( writer ) : <EOL> print ( "<STR_LIT>" ) <EOL> socket = ctx . socket ( zmq . SUB ) <EOL> socket . setsockopt ( zmq . SUBSCRIBE , "<STR_LIT>" ) <EOL> socket . connect ( ADDR ) <EOL> eventlet . sleep ( <NUM_LIT:0.1> ) <EOL> while True : <EOL> msg = socket . recv_pyobj ( ) <EOL> str_msg = "<STR_LIT>" % msg <EOL> writer . write ( str_msg ) <EOL> writer . flush ( ) <EOL> PORT = <NUM_LIT> <EOL> def read_chat_forever ( reader , pub_socket ) : <EOL> line = reader . readline ( ) <EOL> who = '<STR_LIT>' <EOL> while line : <EOL> print ( "<STR_LIT>" , line . strip ( ) ) <EOL> if line . startswith ( '<STR_LIT>' ) : <EOL> who = line . split ( '<STR_LIT::>' ) [ - <NUM_LIT:1> ] . strip ( ) <EOL> try : <EOL> pub_socket . send_pyobj ( ( who , line ) ) <EOL> except socket . error as e : <EOL> if e [ <NUM_LIT:0> ] != <NUM_LIT:32> : <EOL> raise <EOL> line = reader . readline ( ) <EOL> print ( "<STR_LIT>" ) <EOL> try : <EOL> print ( "<STR_LIT>" % PORT ) <EOL> server = eventlet . listen ( ( '<STR_LIT>' , PORT ) ) <EOL> pub_socket = ctx . socket ( zmq . PUB ) <EOL> pub_socket . bind ( ADDR ) <EOL> eventlet . spawn_n ( publish , <EOL> sys . stdout ) <EOL> while True : <EOL> new_connection , address = server . accept ( ) <EOL> print ( "<STR_LIT>" ) <EOL> eventlet . spawn_n ( publish , <EOL> new_connection . makefile ( '<STR_LIT:w>' ) ) <EOL> eventlet . spawn_n ( read_chat_forever , <EOL> new_connection . makefile ( '<STR_LIT:r>' ) , <EOL> pub_socket ) <EOL> except ( KeyboardInterrupt , SystemExit ) : <EOL> print ( "<STR_LIT>" ) </s>
