Skip to content

Latest commit

 

History

History
60 lines (33 loc) · 785 Bytes

README.md

File metadata and controls

60 lines (33 loc) · 785 Bytes

Flask-WebSocket

copyright: (c) 2017 by Damon Chen. license: BSD, see LICENSE for more details.

simple websocket for Flask

Install

git clone https://github.com/damonchen/flask-websocket/

Usage

you must define message with the follow message if you use on decorator:

{
    "event": event for listen
    "data": the event happend with dtaa
}
from flask import Flask
from flask_websocket import WebSocket

app = Flask(__name__)
ws = WebSocket(app)

@ws.on('click')
def click(data):
    print(data)

or you could process raw message by yourself.

from flask import Flask
from flask_websocket import WebSocket

app = Flask(__name__)
ws = WebSocket(app)


@ws.on_raw_message
def raw_message_handler(message):
    print(message)