Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def sendMsg():
- print('send')
- sio.emit('client msg', '我的訊息')
- from flask_socketio import SocketIO, emit
- app = Flask(__name__)
- socketio = SocketIO( app )
- clients = {}
- class client:
- def __init__(self,sid):
- self.sid = sid
- self.connected = True
- def emit(self, event, data):
- emit(event, data, room=self.sid)
- @app.route( '/' )
- def hello():
- # return render_template( './ChatApp.html' )
- global clients
- return str(len(clients))
- def messageRecived():
- print( 'message was received!!!' )
- #Add connected client
- @socketio.on( 'connected' )
- def client_connected():
- print ("%s connected" % (request.sid))
- global clients
- clients[request.sid]= client(request.sid)
- clients[request.sid].emit('response', {'sid':request.sid,'connction':clients[request.sid].connected})
- @socketio.on( 'client msg' )
- def client_message( msg ):
- MSG = str(request.sid) + " 說: "+str(msg)
- print(MSG)
- socketio.emit('response',MSG)
- if __name__ == '__main__':
- socketio.run( app, debug = True )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement