Please ask you is how to solve the problem?
CodePudding user response:
Which give an answerCodePudding user response:
In a separate thread to wait, in addition, if it's TCP, it is best to define a data structure, the specified length, continuous, because TCP flows may tail half a packCodePudding user response:
Accept separate use multithreading, put a single thread, or use a socket non-blocking modeCodePudding user response:
More convenient method is to use some similar libuv libev library, such as processing data in the callback function directly, don't need to care about data exactly what time to, or use the select, epoll to manage such as sockets, open thread receives can also alone,CodePudding user response:
Add a header information, to determine the specific for specific how long messages,CodePudding user response:
With MSG_PEEK recv last parameters, can see whether there is dataCodePudding user response:
Business data and baotou, record data length in baotou,After receiving data to parse the data length, does not receive enough long to continue, or exit the loop,