Flask_sock demo

server.py

import time

from flask import Flask, render_template
from flask_sock import Sock

app = Flask(__name__)
sock = Sock(app)

@app.route('/')
def hello():
    return render_template('index.html')


@sock.route('/echo')
def echo(ws):
    while True:
        data = ws.receive()
        print(data)

        ws.send(data)
        time.sleep(1)

if __name__ == "__main__":

    from gevent import monkey

    monkey.patch_all()
    app.run()

index.html



    
    websocket 测试
    
    



操作记录:

你可能感兴趣的:(Flask_sock demo)