简体   繁体   中英

Unexpected Subcontract and Stick happened in TCP Socket between Python (Server) and Java (Client)

When my colleague's Java(Client) TCP socket program send a package (500KB~1MB) to my Python(Server) TCP socket program, there are cases of subcontracting and sticking. I want to know, is there a universally valid solution to this situation? And what people usually do in this case? I think if it is possible to manually refresh the buffer zone requested by socket function recv(buffer_zone).If I can do that, the program will be free from sticking packages at least.

It's me, and I've solved this problem by Head-Tail Package Mode.
Specifically, when send a serial of data to the server, the client may send a head package including stamp information and data length. When the server receive the head package sent from client, it can know the length that client will send to server, and the server can preper the same length cache for incoming data. When the client send the tail (data) package to the server, the server can depend on the length of the data it knows in advance and take out the data. That's my solution for now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM