add simple multiclient websocket server
This commit is contained in:
parent
bc22af3997
commit
c16e50a645
|
@ -0,0 +1,5 @@
|
|||
debug:
|
||||
flask --app secmsg run --debug
|
||||
|
||||
prod:
|
||||
gunicorn -b :5000 --threads 128 secmsg:app
|
|
@ -0,0 +1,27 @@
|
|||
import os
|
||||
|
||||
from flask import Flask
|
||||
from flask_sock import Sock
|
||||
|
||||
app = Flask(__name__, instance_relative_config=True)
|
||||
sock = Sock(app)
|
||||
clients = []
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return "test"
|
||||
|
||||
@sock.route('/client')
|
||||
def sock_handler(ws):
|
||||
clients.append(ws)
|
||||
|
||||
try:
|
||||
while True:
|
||||
data = ws.receive()
|
||||
for client in clients:
|
||||
if not client is ws:
|
||||
client.send(data)
|
||||
|
||||
except simple_websocket.ws.ConnectionClosed:
|
||||
clients.remove(ws)
|
||||
|
Loading…
Reference in New Issue