Results 1 to 17 of 17

Thread: Bandwidth Monitor issue

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2010
    Posts
    40

    Bandwidth Monitor issue

    Hello,

    So I've run into a small problem with an application that I'm hoping someone can help me with. I apologize ahead of time, my code is crude at best still as I'm still learning.

    The point of my application is to pick up all received packets and have it report to me not only what my current download speed is, but how much I have downloaded in the current session. That said this is where my problem comes in. I started a download that was roughly 93megs and had my monitor running at the same time and not only does the download speed not match what windows shows I am downloading at but the total downloaded packet count does not match up either. It's been frustrating because I'm either missing data or I'm simply not doing something right. The total download amount my application picks up shows roughly 70megs or so downloaded when in fact I downloaded 93.

    I'm running Windows 7 x64 Professional
    Visual Basic 2008

    This is a copy of my code.

    Below the class
    HTML Code:
        Dim VarRecBefore As Integer
        Dim VarDeliverBefore As Integer
        Dim Flag As Boolean = False
    Timer1
    HTML Code:
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles Timer1.Tick
            Dim VarRecAfter As Integer
            Dim VarCalcResult As Integer
            Dim VarDeliverAfter As Integer
    
            Dim properties As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties()
            Dim ipstat As IPGlobalStatistics = properties.GetIPv4GlobalStatistics()
    
            VarDeliverAfter = ipstat.ReceivedPacketsDelivered
            VarRecAfter = ipstat.ReceivedPackets
    
            If Flag = True Then
                If VarRecAfter = VarRecBefore Then
                    uxRecInfo.Text = "0"
                Else
                    VarCalcResult = VarRecAfter - VarRecBefore
                    uxRecInfo.Text = VarCalcResult & "kps"
                    uxTotallbl.Text = VarCalcResult + uxTotallbl.Text
                End If
            Else
                Flag = True
            End If
    
            VarRecBefore = ipstat.ReceivedPackets()
    
            uxforwardlbl.Text = ipstat.ReceivedPacketsForwarded
            uxdeliverlbl.Text = ipstat.ReceivedPacketsDelivered
            uxdiscardedlbl.Text = ipstat.ReceivedPacketsDiscarded
    
        End Sub


  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Bandwidth Monitor issue

    Try this without downloading

    Code:
        Private Sub Timer1_Tick(ByVal sender As System.Object, _
                                ByVal e As System.EventArgs) Handles Timer1.Tick
            Dim properties As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties()
            Dim ipstat As IPGlobalStatistics = properties.GetIPv4GlobalStatistics()
    
            TextBox1.Text = ipstat.ReceivedPackets.ToString("N0")
        End Sub
    Now, how big are the packets?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2010
    Posts
    40

    Re: Bandwidth Monitor issue

    The number shows 662,212 and changes by about 1-2 every second or so without downloading

  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Bandwidth Monitor issue

    For bytes I think you need IPv4InterfaceStatistics.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2010
    Posts
    40

    Re: Bandwidth Monitor issue

    Hrm, I'll try to set that up. Meanwhile I don't suppose you have an example I could work from would you?

    Thank you by the way for the assistance, it is appreciated

  6. #6
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Bandwidth Monitor issue

    Look at my signature> Network Info Probably more than you wanted, but I think rcv bytes is there.
    Last edited by dbasnett; Jan 30th, 2010 at 05:03 PM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  7. #7

    Thread Starter
    Member
    Join Date
    Jan 2010
    Posts
    40

    Re: Bandwidth Monitor issue

    Oh excellent, I will reply back shortly to let you know if this fixed my problem.

    Thanks again

  8. #8

    Thread Starter
    Member
    Join Date
    Jan 2010
    Posts
    40

    Re: Bandwidth Monitor issue

    Hello again, I think I'm close to getting this fixed but I'm having a hard time figuring out how to single out the adapter I need instead of using the for each statement. How can request data specifically from networkcard.name blah

    This is what I'm using to sift now for the card

    Code:
            For Each networkCard As System.Net.NetworkInformation.NetworkInterface _
         In System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces
    
                Dim ipstats As System.Net.NetworkInformation.IPv4InterfaceStatistics = networkCard.GetIPv4Statistics
    
    if networkcard.name = uxAdapterSelectionCmbo.text then
    dostuffhere
    end if
    next

  9. #9
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Bandwidth Monitor issue

    I think you have to iterate through the interfaces to find the one you want.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  10. #10

    Thread Starter
    Member
    Join Date
    Jan 2010
    Posts
    40

    Re: Bandwidth Monitor issue

    Ah, that would explain why I was having trouble figuring out the solution for it lol. Thanks

  11. #11
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Bandwidth Monitor issue

    Code:
            Dim myIntf As NetworkInterface
            For Each networkCard As NetworkInterface In NetworkInterface.GetAllNetworkInterfaces
                If networkCard.Description.Contains("Wireless") Then
                    myIntf = networkCard
                    Exit For
                End If
            Next
            If Not myIntf Is Nothing Then
                Dim foo As IPv4InterfaceStatistics = myIntf.GetIPv4Statistics
                Debug.WriteLine(foo.BytesReceived.ToString)
            End If
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  12. #12

    Thread Starter
    Member
    Join Date
    Jan 2010
    Posts
    40

    Re: Bandwidth Monitor issue

    Once again I appreciate the help with my issues. I tested the data I'm getting with bytes vs what I'm transferring again and seem to still be coming up short with the total transferred by almost half.

    I'm not quite sure what I'm missing here other than there are some other packets I'm not adding in someplace I need to be adding. If I download 93 megs of data I should be able to see that result in my program with what it caught but I'm not.

    Do you have any other suggestions on what I could possibly be missing? Should I be calculating more than just bytesreceived?

    Sorry to be so much trouble :\

    Thanks again

  13. #13
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Bandwidth Monitor issue

    I wouldn't be surprised to see the number higher, but not lower. How do you get the file size? Are you right clicking Properties of the file?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  14. #14

    Thread Starter
    Member
    Join Date
    Jan 2010
    Posts
    40

    Re: Bandwidth Monitor issue

    Yep, says it's exactly 98.1 megs

  15. #15
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Bandwidth Monitor issue

    I downloaded a PDF of about 400KB. The following showed about 800KB.

    Code:
    Imports System.Net.NetworkInformation
    Public Class Form1
        Dim myIntf As NetworkInterface
        Dim strtBytes As Long
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            For Each networkCard As NetworkInterface In NetworkInterface.GetAllNetworkInterfaces
                If networkCard.Description.Contains("Wireless") Then
                    myIntf = networkCard
                    Exit For
                End If
            Next
            Timer1.Interval = 250
        End Sub
        Dim endBytes As Long
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            If Not myIntf Is Nothing Then
                Dim foo As IPv4InterfaceStatistics = myIntf.GetIPv4Statistics
                endBytes = foo.BytesReceived
            End If
            TextBox1.Text = (endBytes - strtBytes).ToString("N0")
        End Sub
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If Timer1.Enabled Then
                Timer1.Stop()
            Else
                Timer1.Start()
                If Not myIntf Is Nothing Then
                    Dim foo As IPv4InterfaceStatistics = myIntf.GetIPv4Statistics
                    strtBytes = foo.BytesReceived
                End If
            End If
        End Sub
    End Class
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  16. #16

    Thread Starter
    Member
    Join Date
    Jan 2010
    Posts
    40

    Re: Bandwidth Monitor issue

    You're right, it must be the way I'm putting together my data. I'm going to play with this some more and be off for the night. Thanks again for helping try to find the problem with my program. Looking at how you handled the data I think I see where my problem is.

    Take it easy, again I appreciated it.

  17. #17
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Bandwidth Monitor issue

    Remember to mark the thread resolved when it is.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width