Receiving all data from socket
Hi!
I tried to receive all data from socket like: 1) Receive the first portion of data 2) Set socket non-blocking 3) Receive data until it gives error 11 (no more data) But that gives strange characters in the result... Is there some better(100% working) way to receive all data? Thank's, Ohmu |
are you sure those strange characters aren't actually being recieved?
|
nope... I am 100% sure of that...
|
What language are you using?
And are you checking how many bytes you receive with each block of data you receive, and making sure to use ONLY that number of bytes? For instance in c, you could end up doing something like this: Code:
char buffer[256]; And if you actually only recv 5 bytes the first 5 bytes will be what you received and the last of them would be garbage and probably displayed if the data wasn't sent as a null-terminated string. (e.g. if the sending app sent "hello" instead of "hello\0" your buffer would end up having so mething like "hellowhatevergarbagewasherebeforethereceiveetc..."). Instead, you would do something like so: Code:
char buffer[256]; |
well.. I fill the array of chars with \0 and then recv data.. but the strange characters aren't at the end only.. they are in the middle too
|
Hmmm... showing us a little bit of your code might be useful.
|
OK.. got it working.. ty all for help
|
All times are GMT -5. The time now is 12:05 PM. |