<s> import os <EOL> import geventwebsocket <EOL> from geventwebsocket . server import WebSocketServer <EOL> def echo_app ( environ , start_response ) : <EOL> websocket = environ . get ( "<STR_LIT>" ) <EOL> if websocket is None : <EOL> return http_handler ( environ , start_response ) <EOL> try : <EOL> while True : <EOL> message = websocket . receive ( ) <EOL> websocket . send ( message ) <EOL> websocket . close ( ) <EOL> except geventwebsocket . WebSocketError , ex : <EOL> print "<STR_LIT>" . format ( ex . __class__ . __name__ , ex ) <EOL> def http_handler ( environ , start_response ) : <EOL> if environ [ "<STR_LIT>" ] . strip ( "<STR_LIT:/>" ) == "<STR_LIT:version>" : <EOL> start_response ( "<STR_LIT>" , [ ] ) <EOL> return [ agent ] <EOL> else : <EOL> start_response ( "<STR_LIT>" , [ ] ) <EOL> return [ "<STR_LIT>" ] <EOL> path = os . path . dirname ( geventwebsocket . __file__ ) <EOL> agent = "<STR_LIT>" % ( geventwebsocket . get_version ( ) ) <EOL> print "<STR_LIT>" % ( agent , path ) <EOL> WebSocketServer ( ( "<STR_LIT>" , <NUM_LIT> ) , echo_app , debug = False ) . serve_forever ( ) </s>
