Re: Socket Send Binary (Jpeg)
On Feb 21, 8:59 pm, "iwasinnihon" <iwasinni...@hotmail.com> wrote:
On Feb 21, 9:23 pm, Ian Collins <ian-n...@hotmail.com> wrote:
iwasinnihon wrote:
Thank you for your help thus far. I have changed it from strlen() to
gcount(). Now I am getting part of the picture. Why can't I get the
entire picture?
Please retain the context of the part of the message you are replying to.
Have a think about what happens to BytesIndex each time something is read.
--
Ian Collins.
You guys have really been helpful. I have altered my code to be as
seen below. It works fine for text documents and jpegs. But, it
won't work for Gifs or PNGs. It only displays part of the picture.
Any ideas why?
while( !file.eof() ) {
char buffer[1024] = "";
int BytesSent = 0;
int BytesIndex = 0;
file.read(buffer, 1024);
int BytesLeft = file.gcount();
while(BytesLeft != 0){
BytesSent = send(sock, &buffer[BytesIndex], BytesLeft, 0);
BytesLeft -= BytesSent;
BytesIndex +=BytesSent;
}
}- Hide quoted text -
- Show quoted text -
This code should work, but I would definitely clean it up some:
* You don't need to initialize a char array you'll be using for
binary data
* Good to move the re-initialization of BytesIndex into your (!
eof) loop; bad to declare all your variables in that loop
* Find a better name ("BytesToSend"?) than BytesLeft, since this
is very ambiguous
I don't know the insides of graphics files, but if you're sending to a
different type of machine, and the files use 16 or 32-bit values, you
may want to consider byte ordering on the other end, which may not
match what you have in your file.
Dana