<s> import logging <EOL> def run_cherrypy_server ( host = "<STR_LIT:127.0.0.1>" , port = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> import cherrypy <EOL> from ws4py . server . cherrypyserver import WebSocketPlugin , WebSocketTool <EOL> from ws4py . websocket import EchoWebSocket <EOL> cherrypy . config . update ( { '<STR_LIT>' : host , <EOL> '<STR_LIT>' : port , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False } ) <EOL> WebSocketPlugin ( cherrypy . engine ) . subscribe ( ) <EOL> cherrypy . tools . websocket = WebSocketTool ( ) <EOL> class Root ( object ) : <EOL> @ cherrypy . expose <EOL> def index ( self ) : <EOL> pass <EOL> config = { <EOL> '<STR_LIT:/>' : { <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : EchoWebSocket <EOL> } <EOL> } <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> logger . warning ( "<STR_LIT>" % ( host , port ) ) <EOL> cherrypy . quickstart ( Root ( ) , '<STR_LIT:/>' , config ) <EOL> def run_cherrypy_server_with_wsaccel ( host = "<STR_LIT:127.0.0.1>" , port = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> import wsaccel <EOL> wsaccel . patch_ws4py ( ) <EOL> run_cherrypy_server ( host , port ) <EOL> def run_cherrypy_server_with_python3 ( host = "<STR_LIT:127.0.0.1>" , port = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> import wsaccel <EOL> wsaccel . patch_ws4py ( ) <EOL> run_cherrypy_server ( host , port ) <EOL> def run_cherrypy_server_with_pypy ( host = "<STR_LIT:127.0.0.1>" , port = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> run_cherrypy_server ( host , port ) <EOL> def run_gevent_server ( host = "<STR_LIT:127.0.0.1>" , port = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> from gevent import monkey ; monkey . patch_all ( ) <EOL> import wsaccel <EOL> wsaccel . patch_ws4py ( ) <EOL> from ws4py . websocket import EchoWebSocket <EOL> from ws4py . server . geventserver import WebSocketWSGIApplication , WSGIServer <EOL> server = WSGIServer ( ( host , port ) , WebSocketWSGIApplication ( handler_cls = EchoWebSocket ) ) <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> logger . warning ( "<STR_LIT>" % ( host , port ) ) <EOL> server . serve_forever ( ) <EOL> def run_python3_asyncio ( host = "<STR_LIT:127.0.0.1>" , port = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> import asyncio <EOL> import wsaccel <EOL> wsaccel . patch_ws4py ( ) <EOL> from ws4py . async_websocket import EchoWebSocket <EOL> from ws4py . server . tulipserver import WebSocketProtocol <EOL> loop = asyncio . get_event_loop ( ) <EOL> def start_server ( ) : <EOL> proto_factory = lambda : WebSocketProtocol ( EchoWebSocket ) <EOL> return loop . create_server ( proto_factory , host , port ) <EOL> s = loop . run_until_complete ( start_server ( ) ) <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> logger . warning ( "<STR_LIT>" % s . sockets [ <NUM_LIT:0> ] . getsockname ( ) ) <EOL> loop . run_forever ( ) <EOL> def run_tornado_server ( host = "<STR_LIT:127.0.0.1>" , port = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> from tornado import ioloop , web , websocket <EOL> class EchoWebSocket ( websocket . WebSocketHandler ) : <EOL> def on_message ( self , message ) : <EOL> self . write_message ( message ) <EOL> app = web . Application ( [ ( r"<STR_LIT:/>" , EchoWebSocket ) ] ) <EOL> app . listen ( port , address = host ) <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> logger . warning ( "<STR_LIT>" % ( host , port ) ) <EOL> ioloop . IOLoop . instance ( ) . start ( ) <EOL> def run_autobahn_server ( host = "<STR_LIT:127.0.0.1>" , port = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> from twisted . internet import reactor <EOL> from autobahn . twisted . websocket import WebSocketServerProtocol , WebSocketServerFactory <EOL> class MyServerProtocol ( WebSocketServerProtocol ) : <EOL> def onMessage ( self , payload , isBinary ) : <EOL> self . sendMessage ( payload , isBinary ) <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> logger . warning ( "<STR_LIT>" % ( host , port ) ) <EOL> factory = WebSocketServerFactory ( "<STR_LIT>" % ( host , port ) ) <EOL> factory . protocol = MyServerProtocol <EOL> reactor . listenTCP ( port , factory ) <EOL> reactor . run ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import argparse <EOL> from multiprocessing import Process <EOL> logging . basicConfig ( format = '<STR_LIT>' ) <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> logger . setLevel ( logging . WARNING ) <EOL> parser = argparse . ArgumentParser ( ) <EOL> parser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> args = parser . parse_args ( ) <EOL> if args . run_all : <EOL> args . run_cherrypy = True <EOL> args . run_cherrypy_wsaccel = True <EOL> args . run_gevent = True <EOL> args . run_tornado = True <EOL> args . run_autobahn = True <EOL> args . run_asyncio = True <EOL> procs = [ ] <EOL> logger . warning ( "<STR_LIT>" % args . run_cherrypy ) <EOL> if args . run_cherrypy : <EOL> p0 = Process ( target = run_cherrypy_server ) <EOL> p0 . daemon = True <EOL> procs . append ( p0 ) <EOL> logger . warning ( "<STR_LIT>" % args . run_gevent ) <EOL> if args . run_gevent : <EOL> p1 = Process ( target = run_gevent_server ) <EOL> p1 . daemon = True <EOL> procs . append ( p1 ) <EOL> logger . warning ( "<STR_LIT>" % args . run_tornado ) <EOL> if args . run_tornado : <EOL> p2 = Process ( target = run_tornado_server ) <EOL> p2 . daemon = True <EOL> procs . append ( p2 ) <EOL> logger . warning ( "<STR_LIT>" % args . run_autobahn ) <EOL> if args . run_autobahn : <EOL> p3 = Process ( target = run_autobahn_server ) <EOL> p3 . daemon = True <EOL> procs . append ( p3 ) <EOL> logger . warning ( "<STR_LIT>" % args . run_cherrypy_pypy ) <EOL> if args . run_cherrypy_pypy : <EOL> p4 = Process ( target = run_cherrypy_server_with_pypy ) <EOL> p4 . daemon = True <EOL> procs . append ( p4 ) <EOL> logger . warning ( "<STR_LIT>" % args . run_cherrypy_py3k ) <EOL> if args . run_cherrypy_py3k : <EOL> p5 = Process ( target = run_cherrypy_server_with_python3 ) <EOL> p5 . daemon = True <EOL> procs . append ( p5 ) <EOL> logger . warning ( "<STR_LIT>" % args . run_cherrypy_wsaccel ) <EOL> if args . run_cherrypy_wsaccel : <EOL> p6 = Process ( target = run_cherrypy_server_with_wsaccel ) <EOL> p6 . daemon = True <EOL> procs . append ( p6 ) <EOL> logger . warning ( "<STR_LIT>" % args . run_asyncio ) <EOL> if args . run_asyncio : <EOL> p7 = Process ( target = run_python3_asyncio ) <EOL> p7 . daemon = True <EOL> procs . append ( p7 ) <EOL> for p in procs : <EOL> p . start ( ) <EOL> logging . info ( "<STR_LIT>" % p . pid ) <EOL> for p in procs : <EOL> p . join ( ) </s>
