Anders and Briegel in Python
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

32 рядки
841B

  1. from flask import Flask, request, render_template, jsonify
  2. from flask_sockets import Sockets
  3. from werkzeug.contrib.cache import SimpleCache
  4. import werkzeug.serving
  5. import json
  6. import abp
  7. cache = SimpleCache(default_timeout = 10000)
  8. cache.set("state", abp.GraphState())
  9. app = Flask(__name__)
  10. sockets = Sockets(app)
  11. @app.route("/")
  12. def index():
  13. return render_template("index.html")
  14. @sockets.route('/diff')
  15. def diff_socket(ws):
  16. while not ws.closed:
  17. message = ws.receive()
  18. print message
  19. ws.send("Hi from the server, you said '{}'".format(message))
  20. @werkzeug.serving.run_with_reloader
  21. def runServer():
  22. from gevent import pywsgi
  23. from geventwebsocket.handler import WebSocketHandler
  24. app.debug = True
  25. ws = pywsgi.WSGIServer(('', 5000), app, handler_class=WebSocketHandler)
  26. ws.serve_forever()