3

I am new to this Socket.io library. May be I am missing something trivial. I am using Flask for server side and javascript for client side. Both sides are able to 'emit' data and call functions on the other side. However, when I have a long running python (it takes about 20 mins to execute) function whose result I want to capture and transmit to client side, looks like the connection is getting dropped. How do I fix this?

Client side, I have this:

var socket = io.connect('http://' + document.domain + ':' + location.port);

On server side:

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app, logger=False, ping_timeout=100, engineio_logger=False)

@socketio.on('long_process')
def long_process(message):
    data_back_to_client = call_long_running_code()
    emit('client_results', {'data': data_back_to_client})

However, by the time call_long_running_code() returns, the connection drops (socket is closed).

How do I make sure the connection persists so that the server side can transmit the results once the long running process is done running. Happy to provide more code or context.

nikki
  • 31
  • 3
  • Edited the question. I call a computationally intensive routine from a python numerical library that takes about 20 mins to return the result. This is what I meant by long running. Thanks. – nikki May 14 '20 at 17:55
  • Typically if your company infrastructure employs any sort of firewall, network requests between client and server are going to be forced dropped after a certain point in time (much less than 20 minutes). This is a security measure against DDOS attacks. Just something to keep in mind with regards to your situation that you may need to look into. – Taplar May 14 '20 at 17:58
  • 1
    Thanks for the quick reply. This is happening even on localhost. – nikki May 14 '20 at 18:19
  • @nikki I'm dealing with the same issue with both frontend and backend on localhost. My routine was only several minutes long, but the connection after running the routine is kept or lost from trial to trial. – Yan Yang Jun 23 '21 at 03:16

0 Answers0