/Django/whaleserver/websocket/main.py

https://github.com/Ezphares/codename-Moving-Whales
Python | 54 lines | 25 code | 10 blank | 19 comment | 1 complexity | 7615c5bd8d55fb843615d9659e89473a MD5 | raw file
  1. #!/usr/bin/env python
  2. #
  3. # Copyright 2009 Facebook
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  6. # not use this file except in compliance with the License. You may obtain
  7. # a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. # License for the specific language governing permissions and limitations
  15. # under the License.
  16. """
  17. Simplified chat demo for websockets.
  18. Authentication, error handling, etc are left as an exercise for the reader :)
  19. """
  20. import logging
  21. import threading
  22. from helpers import *
  23. from websocket import Application
  24. import tornado.ioloop
  25. import tornado.options
  26. from tornado.options import define
  27. from tornado.options import options
  28. logging.basicConfig(
  29. level=logging.INFO,
  30. format='[%(asctime)s] [WEBSOCKET] %(message)s',
  31. )
  32. define("port", default=8888, help="run on the given port", type=int)
  33. define("address", default="0.0.0.0", help="run on the given adress", type=str)
  34. class WhalesWebsocket(threading.Thread):
  35. def __init__(self):
  36. threading.Thread.__init__(self)
  37. def run(self):
  38. app = Application()
  39. app.listen(options.port, options.address)
  40. logging.info("Starting whales websocket server")
  41. tornado.ioloop.IOLoop.instance().start()
  42. if __name__ == "__main__":
  43. websocketThread = WhalesWebsocket()
  44. websocketThread.start()