added ws base code
This commit is contained in:
42
backend/websocket/websocket_base.py
Normal file
42
backend/websocket/websocket_base.py
Normal file
@@ -0,0 +1,42 @@
|
||||
# Copyright (c) 2019. Tobias Kurze
|
||||
|
||||
import logging
|
||||
from flask_socketio import SocketIO, emit
|
||||
|
||||
from backend import app
|
||||
|
||||
logging.basicConfig()
|
||||
|
||||
socketio = SocketIO(app)
|
||||
|
||||
|
||||
@socketio.on('my_event')
|
||||
def test_message(message: dict):
|
||||
print("received msg!")
|
||||
print(message)
|
||||
# emit('my_event', {'data': message['data']})
|
||||
|
||||
|
||||
@socketio.on('my broadcast event', namespace='/')
|
||||
def test_message(message):
|
||||
emit('my response', {'data': message['data']}, broadcast=True)
|
||||
|
||||
|
||||
@socketio.on('connect')
|
||||
def test_connect():
|
||||
print("connected")
|
||||
emit('connect', "antwort")
|
||||
|
||||
|
||||
@socketio.on('disconnect', namespace='/')
|
||||
def test_disconnect():
|
||||
print('Client disconnected')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("running main")
|
||||
socketio.init_app(app, cors_allowed_origins="*")
|
||||
socketio.run(app, host="localhost", port=5000)
|
||||
# ENDE
|
||||
|
||||
print("runnung?!")
|
||||
Reference in New Issue
Block a user