예제 #1
0
 def __init__(self):
     project_root = os.path.dirname(__file__)
     handlers = (
         wsrpc_static(r'/js/(.*)'),
         (r"/ws/", WebSocket),
         (r'/(.*)', tornado.web.StaticFileHandler, {
             'path': os.path.join(project_root, 'static'),
             'default_filename': 'index.html',
         }),
     )
     tornado.web.Application.__init__(self, handlers=handlers)
예제 #2
0
파일: run.py 프로젝트: ei-grad/wsrpc
    def __init__(self):
        project_root = os.path.dirname(os.path.abspath(__file__))
        handlers = (
            wsrpc_static(r'/js/(.*)'),
            (r"/ws/", WebSocket),
            (r'/(.*)', tornado.web.StaticFileHandler, {
                 'path': os.path.join(project_root, 'static'),
                 'default_filename': 'index.html'
            }),
        )

        tornado.web.Application.__init__(
            self,
            handlers,
            xsrf_cookies=False,
            cookie_secret=COOKIE_SECRET,
            debug=options.debug,
            reload=options.debug,
            gzip=options.gzip,
        )
예제 #3
0
    def __init__(self):
        project_root = os.path.dirname(os.path.abspath(__file__))
        handlers = (
            wsrpc_static(r'/js/(.*)'),
            (r"/ws/", WebSocket),
            (r'/(.*)', tornado.web.StaticFileHandler, {
                'path': os.path.join(project_root, 'static'),
                'default_filename': 'index.html'
            }),
        )

        tornado.web.Application.__init__(
            self,
            handlers,
            xsrf_cookies=False,
            cookie_secret=COOKIE_SECRET,
            debug=options.debug,
            reload=options.debug,
            gzip=options.gzip,
        )
예제 #4
0
import tornado.ioloop
import time
from wsrpc import WebSocketRoute, WebSocket, wsrpc_static

class ExampleClassBasedRoute(WebSocketRoute):
    def init(self, **kwargs):
        return self.socket.call('whoAreYou', callback=self._handle_user_agent)

    def _handle_user_agent(self, ua):
        print ua

    def serverSideFunction(self, *args, **kwargs):
        return args, kwargs

WebSocket.ROUTES['test'] = ExampleClassBasedRoute
WebSocket.ROUTES['getTime'] = lambda: time.time()

if __name__ == "__main__":
    http_server = tornado.httpserver.HTTPServer(tornado.web.Application((
        # Генерирует url со статикой q.min.js и wsrpc.min.js
        # (подключать в том же порядке)
        wsrpc_static(r'/js/(.*)'),
        (r"/ws/", WebSocket),
        (r'/(.*)', tornado.web.StaticFileHandler, {
             'path': os.path.join(project_root, 'static'),
             'default_filename': 'index.html'
        }),
    ))
    http_server.listen(options.port, address=options.listen)
    WebSocket.cleapup_worker()
    tornado.ioloop.IOLoop.instance().start()
예제 #5
0
    def __init__(self):
        handlers = (
            wsrpc_static('/static/(.*)'),
        )

        tornado.web.Application.__init__(self, handlers)