简体   繁体   中英

Socket send data but the recv program dont work well

i created 2 programs, one to send and the other to recv the data. So,

The portion to recv data is:

while ((recvMsgSize = sock->recv(echoBuffer, RCVBUFSIZE))>0) {
   write(fileno(stdout), echoBuffer, recvMsgSize);
}

If i use it to recv a large file data, it works well, with small amount of data it dont work. I know the problem is with the recv portion because if i use netcat to recv data it works well, it recv the entire data. Is there any other way to receive the data?

Thanks

I would guess your socket is blocking and recv is waiting for RCVBUFSIZE bytes to be sent. You should send the size of the file that is going to be sent first and then count how much data you've received and only request the remaining portion when what you're missing is less than RCVBUFSIZE bytes.

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