Get Down/Upstream

This is a discussion on Get Down/Upstream within the C++ Programming forums, part of the General Programming Boards category; I wanna make a program that counts the data that was downloaded/uploaded. ex: when i download a file from 12Mb, ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    7

    Get Down/Upstream

    I wanna make a program that counts the data that was downloaded/uploaded.
    ex: when i download a file from 12Mb, the counter says 12Mb.
    when i download another file, it counts up with the previous number of 12.
    I wanna use it in a console window.
    Where to start?

    Unlimited4s

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    It is simple enough to maintain a counter, just read binary data of a certain size into a buffer and increment your counter for every completed read. If the read is not completed, divide what you got by the size of the buffer and add that piece to the total:
    Code:
    while ( ( len = fread ( buffer, 1, sizeof buffer, in ) ) != 0 ) {
      if ( len < sizeof buffer )
        count += (double)len / sizeof buffer;
      else
        count++;
    }
    -Prelude
    My best code is written with the delete key.

  3. #3
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    I think he's talking about monitoring traffic in other programs such as IE.

    Not sure how to do this but first thing I would say is learn winsock if you don't already know it.

  4. #4
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    preluse wheres ur old avatar, i liked it! the ball is gay. the anime gurl wasnt
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  5. #5
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    Originally posted by Klinerr1
    the ball is gay.
    prelude is female. You have no right to talk with your dancing bart anyway. Aside from that you are clearly mentally challenged.

  6. #6
    Shadow12345
    Guest
    Prelude is awesome. I agree with Fill

  7. #7
    Shadow12345
    Guest
    I don't even understand prelude's code. What is fread? is that a function specific for internet or...?

    fread ( buffer, 1, sizeof buffer, in );

    what are the parameters supposed to be? I mean what do they do? What is the type of the last one? I've seen some functions that take characters for input such as system("cls"). Is that what the in is sorta like??

    [edit]
    size_z fread(void *, size_t, size_t, FILE*)
    /[edit]

    uhh so it returns a size_t which is a buffer? what is the first parameter? a pointer to void? silly. and then the last one is the directory or something that you want something saved? hmm

    instead of saying "eff-read" say it "freeed" its funny *giggle*
    Last edited by Shadow12345; 08-22-2002 at 04:03 PM.

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >What is fread?
    fread is a function used for binary input, it takes the address of a buffer to write to, the number of items to read for that call, the size of each item to be read, and an input stream to read from. It returns the number of bytes read. You can think of it as the fgets for binary data.

    -Prelude
    My best code is written with the delete key.

  9. #9
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    i never liked the anime avatar, but the ball is cool
    hello, internet!

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21