secmsg/secmsg/__init__.py

28 lines
514 B
Python

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)