mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
improved multiclient support and reconnecting
This commit is contained in:
parent
3b9db2980c
commit
8b49fc4f8e
1 changed files with 21 additions and 2 deletions
|
@ -127,17 +127,36 @@ def post_ping():
|
||||||
# @app.route('/rig/frequency', methods=['POST'])
|
# @app.route('/rig/frequency', methods=['POST'])
|
||||||
# @app.route('/rig/test_hamlib', methods=['POST'])
|
# @app.route('/rig/test_hamlib', methods=['POST'])
|
||||||
|
|
||||||
|
|
||||||
|
# our client set which contains all connected websocket clients
|
||||||
|
client_list = set()
|
||||||
|
# our transmit function which also handles client management
|
||||||
|
def transmit_sock_data(data):
|
||||||
|
try:
|
||||||
|
for client in client_list:
|
||||||
|
try:
|
||||||
|
client.send(data)
|
||||||
|
except Exception:
|
||||||
|
# print("client not connected anymore")
|
||||||
|
client_list.remove(client)
|
||||||
|
except RuntimeError:
|
||||||
|
# print("set changed during iteration")
|
||||||
|
pass
|
||||||
|
|
||||||
# Event websocket
|
# Event websocket
|
||||||
@sock.route('/events')
|
@sock.route('/events')
|
||||||
def sock_events(sock):
|
def sock_events(sock):
|
||||||
# it seems we have to keep the logics inside a loop, otherwise connection will be terminated
|
# it seems we have to keep the logics inside a loop, otherwise connection will be terminated
|
||||||
|
client_list.add(sock)
|
||||||
while True:
|
while True:
|
||||||
ev = app.modem_events.get()
|
ev = app.modem_events.get()
|
||||||
sock.send(ev)
|
transmit_sock_data(ev)
|
||||||
|
|
||||||
|
# FFT Websocket
|
||||||
@sock.route('/fft')
|
@sock.route('/fft')
|
||||||
def sock_fft(sock):
|
def sock_fft(sock):
|
||||||
# it seems we have to keep the logics inside a loop, otherwise connection will be terminated
|
# it seems we have to keep the logics inside a loop, otherwise connection will be terminated
|
||||||
|
client_list.add(sock)
|
||||||
while True:
|
while True:
|
||||||
fft = app.modem_fft.get()
|
fft = app.modem_fft.get()
|
||||||
sock.send(fft)
|
transmit_sock_data(fft)
|
||||||
|
|
Loading…
Reference in a new issue