mirror of
https://github.com/kennethreitz/flask-sockets.git
synced 2026-06-05 23:10:16 +00:00
29 lines
515 B
ReStructuredText
29 lines
515 B
ReStructuredText
Flask-Sockets
|
|
=============
|
|
|
|
Elegant WebSockets for your Flask apps.
|
|
|
|
The Problem
|
|
-----------
|
|
|
|
Serving WebSockets in Python were really difficult.
|
|
|
|
.. code-block:: python
|
|
|
|
from flask import Flask
|
|
from flask_sockets import Sockets
|
|
|
|
app = Flask(__name__)
|
|
sockets = Sockets(app)
|
|
|
|
@sockets.route('/echo')
|
|
def echo_socket(ws):
|
|
while True:
|
|
message = ws.receive()
|
|
ws.send(message)
|
|
|
|
@app.route('/')
|
|
def hello():
|
|
return 'Hello World!'
|
|
|
|
Now they're not. |