Skip to content

Commit

Permalink
added server pushed events to example app
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Mar 16, 2014
1 parent 4f9d0fa commit 3c06500
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions example/app.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import time
from threading import Thread
from flask import Flask, render_template, session, request
from flask.ext.socketio import SocketIO, emit, join_room, leave_room

app = Flask(__name__)
app.debug=True
app.debug = True
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)


def background_thread():
"""Example of how to send server generated events to clients."""
count = 0
while True:
time.sleep(10)
count += 1
socketio.emit('my response',
{'data': 'Server generated event', 'count': count},
namespace='/test')


@app.route('/')
def index():
return render_template('index.html')
Expand Down Expand Up @@ -64,5 +77,5 @@ def test_disconnect():


if __name__ == '__main__':
Thread(target=background_thread).start()
socketio.run(app)

0 comments on commit 3c06500

Please sign in to comment.