/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. from circuits.net.events import write
  3. from circuits import Component, Debugger
  4. from circuits.web.dispatchers import WebSocketsDispatcher
  5. from circuits.web import Controller, Logger, Server, Static
  6. class Echo(Component):
  7. channel = "wsserver"
  8. def read(self, sock, data):
  9. self.fireEvent(write(sock, "Received: " + data))
  10. class Root(Controller):
  11. def index(self):
  12. return "Hello World!"
  13. app = Server(("0.0.0.0", 8000))
  14. Debugger().register(app)
  15. Static().register(app)
  16. Echo().register(app)
  17. Root().register(app)
  18. Logger().register(app)
  19. WebSocketsDispatcher("/websocket").register(app)
  20. app.run()