<s> import uuid <EOL> import sys <EOL> from twisted . python import log <EOL> from twisted . internet import reactor <EOL> from twisted . web . server import Site <EOL> from twisted . web . wsgi import WSGIResource <EOL> from flask import Flask , render_template <EOL> from autobahn . twisted . websocket import WebSocketServerFactory , WebSocketServerProtocol <EOL> from autobahn . twisted . resource import WebSocketResource , WSGIRootResource <EOL> class EchoServerProtocol ( WebSocketServerProtocol ) : <EOL> def onMessage ( self , payload , isBinary ) : <EOL> self . sendMessage ( payload , isBinary ) <EOL> app = Flask ( __name__ ) <EOL> app . secret_key = str ( uuid . uuid4 ( ) ) <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> def page_home ( ) : <EOL> return render_template ( '<STR_LIT>' ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> log . startLogging ( sys . stdout ) <EOL> wsFactory = WebSocketServerFactory ( u"<STR_LIT>" ) <EOL> wsFactory . protocol = EchoServerProtocol <EOL> wsResource = WebSocketResource ( wsFactory ) <EOL> wsgiResource = WSGIResource ( reactor , reactor . getThreadPool ( ) , app ) <EOL> rootResource = WSGIRootResource ( wsgiResource , { '<STR_LIT>' : wsResource } ) <EOL> site = Site ( rootResource ) <EOL> reactor . listenTCP ( <NUM_LIT> , site ) <EOL> reactor . run ( ) </s>
