Thread: File Through Winsock & Progress on bar

  1. #1
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339

    Red face File Through Winsock & Progress on bar

    Hey,

    How do you send a file through a winsock connection. I mean if it was a simple text file i know i could just read it in then use send() to send it through, but say its a bigger file such as a bitmap that i can just do that with or can I? If i can do it like that can someone explain how it is done.

    Also i want to display the progress of the transfer on a progress bar. I can make a progress bar but i dont know how to make it interact with the file transfer and show its progress.


    Thanks for any help

    Cheers
    TNT
    TNT
    You Can Stop Me, But You Cant Stop Us All

  2. #2
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    Posts
    186
    Usually transfers of larger files include one large loop that reads from the hard drive (or memory if you've read the entire file in), sends the data, and calculates its progress and rate. So yes, you could do the same with a bitmap, but don't send it all at once.

    The Winsock function TransmitFile() allows you to send a block of data before and after a transfer along with the file. There is, however, no way to track its progress or calculate a rate.

    Set the progress bar's maximum amount to the size of the file, and the minimum amount to zero (or to an offset if the transfer begins in the middle of a file). Every time the bar needs repainting, see how much has been downloaded with a global variable the send loop continuously updates, and set that as the bar's current value.
    "Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    When we send a file I get the size as an int first, I set the progressbar to this size. As data is read, send the size rec to the progress bar.

    I have a VERY complicated function for reading in the files. They are of different sizes, sockets and types.

    while(Data_Used<Data_Read)

    switch(iBuffer)

    case(1)
    read the sizeof(int)=total_incomming
    Data_Used+=sizeof(int)
    alloc mem for outgoing buffer this size
    iBuffer++

    case (2)
    copy mem into outgoing buffer
    //here it gets tricky as must allow for not getting all the data in one read
    //also for end of one item and start of another in same read
    Data_Used+=Data_Copied
    if(Data_Copied==total_incomming)
    iBuffer++

    case (3)
    send to app funct to deal with data
    iBuffer=1
    free outgoing buffer

    end of while loop
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    164
    Storing the same as an int means that you can't have files larger than 32k. Of course some compilers has 32-bit ints but using long is better.
    // Gliptic

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    True, I forgot we are compressing them for transfer.

    Should use long.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File Writing Problem
    By polskash in forum C Programming
    Replies: 3
    Last Post: 02-13-2009, 10:47 AM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM