I am sure that does not happen in a related example. Apparently, it uses synchronous asynchronous sockets. I do not see any callbacks or similar in the code. You may need to rethink whether you need synchronous or asynchronous sockets :).
The problem at hand implies that your functions are trying to read / write to the buffer until the transmission / reception of the network is complete. Try using the callback functions included in async socket. For instance.
source share