Anders and Briegel in Python
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

32 linhas
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()