Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import socketio
  2. import eventlet
  3. from flask import Flask, render_template
  4. import json
  5. import time
  6.  
  7. sio = socketio.Server()
  8. app = Flask(__name__,static_folder='static')
  9.  
  10. def background_thread():
  11.         sio.sleep(1)
  12.         timer = (int(time.time()))
  13.         sio.emit('message', json.dumps({'timestamp': timer}))
  14.         sio.start_background_task(background_thread)
  15.  
  16. sio.start_background_task(background_thread)
  17.  
  18. @app.route('/')
  19. def index():
  20.     return render_template('index.html')
  21.  
  22. @sio.on('connect')
  23. def connect(sid, environ):
  24.     print('connect ', sid)
  25.  
  26. @sio.on('disconnect')
  27. def disconnect(sid):
  28.     print('disconnect ', sid)
  29.  
  30.  
  31. if __name__ == '__main__':
  32.     app.debug = True
  33.     app = socketio.Middleware(sio, app)
  34.  
  35.     eventlet.wsgi.server(eventlet.listen(('127.0.0.1', 3000)), app)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement