I'm using a Python based socketio server and JS socketio client. The workflow looks roughly like this:
client emits <<action1>>
-> server receives <<action1>>
-> server performs some calculations
-> server emits <<action2>>
-> client receives <<action2>>
It should work in a loop.
The problem is that for some reason the last step isn't performed, client doesn't seem to catch action2
event. I can see that it has been fired from the server logs, they state that: emitting event "action2" to all [/]
Server:
@sio.on('action1')
def handle_analysis():
... some calculations ...
sio.emit('action2')
Client:
import { io } from "socket.io-client";
export const socket = io("http://localhost:5550",
{
timeout: 200000
});
async runCalculations() {
console.log('progress1');
let stdoutChunks: string = '';
const getCalculations = () => {
socket.emit('action1');
return new Promise((resolve, reject) => {
socket.on('action2', (msg) => {
stdoutChunks += msg;
resolve(stdoutChunks);
})
});
};
await getCalculations()
console.log('progress2');
return {};
}
progress2
is never logged, because js keeps on awaiting the getCalculations
function.
Can anyone point where the issue might be?
Each calculation takes roughly 50 seconds, I wonder if that might be the cause.
I used same approach for different events that take much less time and it works perfectly, server communicates with the client without problems.