kishore
kishore

Reputation: 672

Winsock TCP application buffer

I have been working with the winsock api recently and I found that when I increase the sender's buffer size and pad the unused bytes with zero, the receiver also appends those zeroes to the end of the file. If the application buffer I use is more, say 3072 the file I receive at the other end seems to be corrupted and it seems obvious because of appending zeroes. But it worked fine with buffer of 2048, 1024 and in those cases too zeroes were appended before sending. how come one be corrupted and not the other?

Upvotes: 0

Views: 143

Answers (1)

user207421
user207421

Reputation: 310980

when I increase the sender's buffer size and pad the unused bytes with zero, the receiver also appends those zeroes to the end of the file.

So the bytes weren't 'unused' at all. You sent them. You used the wrong count in the send function call.

If the application buffer I use is more, say 3072 the file I receive at the other end seems to be corrupted and it seems obvious because of appending zeroes.

Correct.

But it worked fine with buffer of 2048, 1024 and in those cases too zeroes were appended before sending. how come one be corrupted and not the other?

Because you have a bug in your code that was only exposed by the larger buffer size. Probably the file you sent was a multiple of 2048 bytes so your end-of-file bug wasn't exposed.

Without seeing your code it is impossibly to be sure, but most probably you are ignoring the count returned when you read from the file, and sending the entire buffer, instead of just sending 'count' bytes. This fails at end of file, but it can also fail any other time he read didn't fill the buffers which it isn't obliged to do.

Upvotes: 1

Related Questions