Strictly necessary cookies are on by default and cannot be turned off. Functional, Performance and Tracking/targeting/sharing cookies can be turned on below based on your preferences (this banner will remain available for you to accept cookies). You may change your cookie settings by deleting cookies from your browser. Then this banner will appear again. You can learn more details about cookies HERE.
Strictly necessary (always on)
Functional, Performance and Tracking/targeting/sharing (default off)
I solved it now by ignoring the message received callback.
I am still using the callback for connect and disconnect.
When I receive a connect I accept the socket and then create a thread for this client, which continuously waits for data, and this seems to get it all and work faster than the callback.
When disconnect is called using the callback, the receive socket already detected it is closed and the thread executes WICED_END_CURRENT_THREAD. On the place I fetch the disconnect callback I then delete the thread that I created for the client to receive data.
This approach solves the above problem for me, maybe it is useful for someone else as well.