PageRenderTime 31ms CodeModel.GetById 27ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/web/websockets.py

https://bitbucket.org/prologic/circuits/
Python | 29 lines | 19 code | 9 blank | 1 comment | 0 complexity | a3c9da5cc663d53858113fe22c60a8fc MD5 | raw file
 1#!/usr/bin/env python
 2
 3from circuits.net.events import write
 4from circuits import Component, Debugger
 5from circuits.web.dispatchers import WebSocketsDispatcher
 6from circuits.web import Controller, Logger, Server, Static
 7
 8
 9class Echo(Component):
10
11    channel = "wsserver"
12
13    def read(self, sock, data):
14        self.fireEvent(write(sock, "Received: " + data))
15
16
17class Root(Controller):
18
19    def index(self):
20        return "Hello World!"
21
22app = Server(("0.0.0.0", 8000))
23Debugger().register(app)
24Static().register(app)
25Echo().register(app)
26Root().register(app)
27Logger().register(app)
28WebSocketsDispatcher("/websocket").register(app)
29app.run()