0

I recently started using flask-sockets in my flask application with native WebSocket API as client. I would like to know if there is proper way to send ping requests at certain intervals from the server as keepalive?

When going through the geventwebsocket library, I noticed the definition handle_ping(...), but it's never called. Is there a way to determine a ping interval on WS?

I see my sockets dying after a minute and a half inconsistently sometimes.

@socket_blueprint.route('/ws', defaults={'name':''})
def echo_socket(ws):
    while not ws.closed:
        ws_list.append(
        msg = ws.receive()
        ws.send(msg)

I could probably spin up a separate thread and send ping opcodes manually every 30 seconds to the clients if I keep them in a list, but I feel like there'd be a better way to handle that..

Jonathan Hamel
  • 1,393
  • 13
  • 18

1 Answers1

1

In service, create a thread in this thread send some data(any data) to client. If client already disconnected,after 15s the server will receive closed. I haven't find any method about ping in gevent websocket or flask-sockets. So take this method.

Llex
  • 1,770
  • 1
  • 12
  • 27
刘占晨
  • 11
  • 1