I\'m working on a scientific experiment where about two dozen test persons play a turn-based game with/against each other. Right now, it\'s a Python web app with a WSGI inte
but I'm not sure about the architecture for mixing WSGI and websockets
I made it
use WSocket
http 1.1 Server. for Middleware, Framework, Appexample using bottle web framework and WSocket middleware
from bottle import request, Bottle
from wsocket import WSocketApp, WebSocketError, logger, run
from time import sleep
logger.setLevel(10) # for debugging
bottle = Bottle()
app = WSocketApp(bottle)
# app = WSocketApp(bottle, "WAMP")
@bottle.route("/")
def handle_websocket():
wsock = request.environ.get("wsgi.websocket")
if not wsock:
return "Hello World!"
while True:
try:
message = wsock.receive()
if message != None:
print("participator : " + message)
wsock.send("you : "+message)
sleep(2)
wsock.send("you : "+message)
except WebSocketError:
break
run(app)