Thread: Corrupted binary data

  1. #1
    Registered User
    Join Date
    Apr 2006

    Corrupted binary data

    The file sender, when sending the data locally(, or my IP address), is sent fine and works. However, when I try to send it to another computer, the data is always corrupted. Everything is sent and all, but the application in which it's suppose to open says the data is corrupted. If anyone could give me an idea of why this is happening, that would be great.


  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Out of scope
    You have to convert the data to network byte order before sending it and back to host byte order after recieving it. Look into htons(), htonl(), ntohs(), ntohl(), etc...
    Last edited by SlyMaelstrom; 05-03-2006 at 12:46 PM.
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Apr 2006
    I'll try that, thanks.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > sprintf(charfilesize, "%d", filesize);
    Look at where charfilesize is pointing - nowhere.

    > int thesend = send(mysocket, buffer, sizeof(buffer), 0);
    You're assuming that send() always sends everything on the first call - this isn't true.
    Check how much you sent.
    Also, what about files which are not a multiple of 1024 in length?

    > recv(mysocket, writebuffer, 1024, 0);
    Likewise, just because you ask for 1024 doesn't mean you get 1024.
    In particular, the last block is almost always going to be less than this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. store binary data in program...
    By Abda92 in forum C Programming
    Replies: 9
    Last Post: 03-23-2008, 10:33 AM
  2. Bitmasking Problem
    By mike_g in forum C++ Programming
    Replies: 13
    Last Post: 11-08-2007, 12:24 AM
  3. How to write image data to binary PGM file format(P5)?
    By tommy_chai in forum C Programming
    Replies: 6
    Last Post: 11-03-2007, 10:52 PM
  4. Binary comparison
    By tao in forum Windows Programming
    Replies: 0
    Last Post: 06-28-2006, 12:10 PM
  5. Replies: 4
    Last Post: 06-14-2005, 05:45 AM