Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  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. @app.route('/')
  17. def index():
  18.     return render_template('index.html')
  19.  
  20. @sio.on('connect')
  21. def connect(sid, environ):
  22.     print('connect ', sid)
  23.  
  24. @sio.on('disconnect')
  25. def disconnect(sid):
  26.     print('disconnect ', sid)
  27.  
  28.  
  29. if __name__ == '__main__':
  30.     app.debug = True
  31.     app = socketio.Middleware(sio, app)
  32.  
  33.     eventlet.wsgi.server(eventlet.listen(('127.0.0.1', 3000)), app)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement