#NEWLINE# def chat( host = 'localhost' , port = 1234 , coro = None ) : #NEWLINE# #INDENT# coro . set_daemon ( ) #NEWLINE# sock = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) #NEWLINE# sock . setsockopt ( socket . SOL_SOCKET , socket . SO_REUSEADDR , 1 ) #NEWLINE# sock = asyncoro . AsynCoroSocket ( sock ) #NEWLINE# sock . bind ( ( host , port ) ) #NEWLINE# sock . listen ( 128 ) #NEWLINE# logging . debug ( 'server at %s' , str ( sock . getsockname ( ) ) ) #NEWLINE# clients = set ( ) #NEWLINE# try : #NEWLINE# #INDENT# while True : #NEWLINE# #INDENT# ( conn , addr ) = ( yield sock . accept ( ) ) #NEWLINE# clients . add ( conn ) #NEWLINE# asyncoro . Coro ( client_send , clients , addr ) #NEWLINE# #UNINDENT# #UNINDENT# except : #NEWLINE# #INDENT# for client in clients : #NEWLINE# #INDENT# logging . debug ( 'closing %s' , client . _fileno ) #NEWLINE# client . shutdown ( socket . SHUT_RDWR ) #NEWLINE# client . close ( ) #NEWLINE# #UNINDENT# raise