?
Solved

Bytes Sent

Posted on 2003-03-02
11
Medium Priority
?
463 Views
Last Modified: 2013-11-13
How do I access the Bytes Sent/Received for a session?

I would like to be able to place this information in a label on a form window.
0
Comment
Question by:cMh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
11 Comments
 
LVL 1

Expert Comment

by:J-Man
ID: 8053903
I don't think either inet control or winsock control keeps track.  You'll have to make a variable for each, add the count as the files xfer, then update your label in a timer control (say every 100 ms for the timer.interval property.)

For example:

Public lBytesSent as long
Public lBytesRec as long

Public Timer1_Timer()
   labelSent.Caption = Format(lBytesSent) & " bytes sent"
   labelRec.Caption = Format(lBytesRec) & " bytes received"
   'next 2 lines optional
   labelSent.Refresh
   labelRec.Refresh
End Sub

Public GetFile(strURL as string)
'assuming your using inet control
Dim myString as String
  inet1.URL = strURL
  myString = Inet1.OpenURL
  lBytesRec = lBytesRec + Len(myString)
End Sub
'need similar subroutine for sending file
0
 

Author Comment

by:cMh
ID: 8056237
The amount tracked would be the values shown in the connection box in windows (the one that appears when you connect to the internet via a modem next to the clock).

My program doesn't actually download anything so tracking an Inet/Winsock control wouldn't work I don't think.

Any other ideas?
0
 
LVL 1

Expert Comment

by:J-Man
ID: 8084016
Hmmm, even if you haven't told it to download a file, you are still downloading even if you are simply viewing a web-page.  For example, on one web page you would be downloading the html file and any pictures, audio or video on the page even though they may only be stored temporarily.

I don't know how to access the actual numbers from the dialup networking icon in the system tray.  If all you want is a window that shows those numbers, why not simply right-click the icon and select "Status"; this will show a window with the bytes transferred, duration and speed of the connection.  Otherwise, you would probably have to find the thread for the internet connection and hope it uses a Public variable that other apps can read.  I would guess that microsoft would NOT make the variables public simply so other apps don't change the value.

This site has a shareware utility that does what you want (and more.)
http://www.simtel.net/pub/pd/15144.html

If you still want to create your own program, I suggest using a winsock control with a callback subroutine, your callback sub will be activated when anything is received on the selected port and you can check the buffer to see how many bytes have been received.  I could probably round up some example links for that.

Are you using a webbrowser control in your program or do you want this to work for any internet transfer?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:cMh
ID: 8087045
I am aware that this would monitor all transfers including web pages... this is what I would like.

Clicking on the icon is an option but being lazy I would like it to just be updated in the window I am working in (in other words my program window)...

I am interested by the callback option.  Can you see if you can find anything here?  I have looked but can't find anything.

Basically all I want to do is display the details from the DUN icon to a label in my program.
0
 
LVL 1

Expert Comment

by:J-Man
ID: 8095215
OK, don't worry about using winsock, (but if you are still interested see the bottom of this post...)

I found a related question with code here:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20090180.html
Originally posted at http://www.mvps.org/vbnet/
I think it is from the "FTP: Downloading Files via FTP with Progress Display Callback" page.

The code is a little long, but I think it should do what you want.  Be sure to let me know if this works for you.

--------
more about winsock:

(the callback routine I mentioned is the Winsock1_DataArrival event, however I beleive you will have to initiate the connection with the winsock control and assign a socket, then it will only receive data from that socket - basically you would have to handle all the data with your program which sounds like more than you really need to do.)

'DataArrival event example:
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim DataRecvd as String
    Debug.Print "DataArrival"
    'Recieve the data
    Winsock1.GetData DataRecvd
    Debug.Print "recieved data ="; DataRecvd
    Debut.Print "bytes received =" & Format(bytesTotal)
    'Do something with the data
End Sub

I recommend viewing http://www.vbip.com for more examples/info on using the winsock control, or see the mvps site mentioned above.
0
 

Author Comment

by:cMh
ID: 8097203
Thanks again for your help J-Man but this example seems to be just if you wanted to download via FTP.  It is essentially a download manager.

All I really want is to have the Bytes Sent/Received from the DUN icon placed on a label in my program.

Any other ideas?
0
 
LVL 1

Expert Comment

by:J-Man
ID: 8099768
OK, one more strategy.  See the page below and download the source code from the link at the top labeled "Download Interfaces Info project".

http://www.vbip.com/iphelper/get_interface_info.asp

This program uses the GetIFTable function that you can learn more about here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iphlp/iphlp/getiftable.asp

When I ran this program, I got an overflow, but it is easy to fix.  The line in CipHelper class that reads:
objInterface.LastChange = .dwLastChange
should be changed to:
objInterface.LastChange = Len(.dwLastChange)

Also, I should remind you that you need to select the correct interface, usually PPP/SLIP interface for dial-up modem.  You can probably do without the combobox and just tell it which adapter/interface to use programatically.

The info you want (bytes sent, bytes received) are in labels at the bottom of the form which differs from the DUN numbers by about 10% (probably due to either packet headers or retransmissions).  I believe the numbers are stored in the variables m_lngBytesReceived and m_lngBytesSent.

You will have to do a lot of cutting and pasting into your program unless you simply add the class files to your program.  You can certainly trim out a lot, but be careful or you will have a lot of debugging to do.  I think you also must have dial-up networking version 1.3 installed.

This should finally be the accepted answer.  ;-)
0
 

Author Comment

by:cMh
ID: 8104878
This isn't correct either as this value shows the total amount downloaded since the computer was switched on and not in the session like I need.  Incidentally I think there is a much simpler way of getting the "total since the computer was switched on value"...

I can't believe moving those numbers from the DUN to my program is so difficult but I have been unable to trak down how it is done as well!
0
 
LVL 1

Accepted Solution

by:
J-Man earned 300 total points
ID: 8114615
It is correct (my last post).

If you want only the data for the session, then put a commandbutton on your form called "Reset" and click it before you dial, or make a Reset sub and call this upon loading your form then shell the DUN.
Like....

Public OldValueSent As Long
Public OldValueRec As Long
Public SessionSent As Long
Public SessionRec As Long

Private Sub Reset_Click()
    OldValueSent = m_lngBytesSent
    OldValueRec = m_lngBytesReceived
End Sub

Private Sub UpdateLabel()
    SessionSent = m_lngBytesSent - OldValueSent
    SessionRec = m_lngBytesReceived - OldValueRec
    MyLabelSent.Caption = Format(SessionSent)
    MyLabelRec.Caption = Format(SessionRec)
End Sub
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 9012072
Hi cMh,
It appears that you have forgotten to close this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept J-Man's comment(s) as an answer.

cMh, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept THIS comment as an answer.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Expert Comment

by:J-Man
ID: 9124387
My last 2 comments work the best.  I have tested the code (with noted change in line 6 of second to last comment.)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question