Thread: data curroption

  1. #1
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342

    data curroption

    I have written client/server progs to transfer files . Through this program, I am now able to transfer files larger than 1 MB from my machine to any remote machine where the client program is running without any problem..


    The other requirement of the program is to read a file that exists in hte remote machine.. I have used the same concept even for that code and i have traced it many times to find any pit-falls, but I am not able to transfer files greater than 5000 bytes without the data being curropted..
    I also noted these things..
    1 . the data in the packets that is being sent from hte remote machine is valid, thats not the case after I receive them here for the final few packets
    2. also, the numbers returned by send() and recv() match for a large number of packets sent , the mismatch occurs in the last few packets..
    By curropted ,I mean some sections of the file getting repeated right at the end , or after the actual file has been transfered, a part of the file also gets added.
    The lan is a standard one, I can do my usual ftp and telnet stuff.

    I cud have posted the code , but its quite bulky..
    Has anyone faced this problem before, please help

  2. #2
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    i would like to add one more thing here :
    I was instructed break up large files into chunks of 1000 bytes and then use the send() iteratively ..
    only in the in the last packet, the send() and recv() functions return different values..

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Deja-vu again and again?
    http://cboard.cprogramming.com/showthread.php?t=80083
    http://cboard.cprogramming.com/showthread.php?t=80179

    1. Are you using a TCP or UDP connection?

    2. Do you send the length of the file first, then the contents of the file?
    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.

  4. #4
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    forget about that ,i cud fix it..

  5. #5
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    By curropted ,I mean some sections of the file getting repeated right at the end , or after the actual file has been transfered, a part of the file also gets added.
    If the answer to (2) is no, perhaps you're outputting the receive-buffer before checking the error status of recv(). Or, maybe you're assuming that (packet_size) bytes have been received instead of checking recv()'s return value. That would lead to (in the first case) the last packet being repeated, or (in the second case) a segment of the second-last packet being repeated.

    *EDIT: Actually, the second case would lead to random unpredictable bits of data strewn all throughout your output, and a predictable segment of the second-last packet being appended to the last.

    Judging from the previous threads, this is *probably* the problem.

    *EDIT2: Actually, the 'predictable' segment will *not* occur if:
    (filesize % buffersize) == (unpredictable_bytes % buffersize).
    See if you can figure out why.
    Last edited by Hunter2; 06-30-2006 at 07:13 AM.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  3. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 08:55 PM
  4. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM
  5. Replies: 1
    Last Post: 07-31-2002, 11:35 AM