Returning UDP traffic in real-time and control latency

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Wayne M J

    Returning UDP traffic in real-time and control latency

    I am capturing syslogd traffic from a firewall/router, if I display the
    results to Console it runs fine and dandy, but the minute I need it to go to
    a ListBox, DataGrid or even a text box problems begin to arise.

    It comes down to what looks like latency, but the control are not fast
    enough to refresh in time to display all of the packet contents.

    I have tried threading the function, but that only increases the latency.
    At one point I seriously thought it was my code:
    While True
    Dim data(1024) As Byte
    Dim recv As Integer
    recv = s.ReceiveFrom(d ata, ep)
    'iep = ep '*** Only needed to get the source of the traffic ***
    Dim strData As String = System.Text.Enc oding.ASCII.Get String(data, 0,
    recv)
    Console.WriteLi ne(strData)
    End While

    That is the business end of the code, and there is not much tweaking there
    that can be done to speed up returns.

    I have tried this code on a P4, a P3 and an old P2 with the same results,
    the controls just did not refresh fast enough such that the next line of
    traffic could be added.

    I have compiled the code in both Debug (very bad latency about 2 messages in
    3 were lost) and Release (1 in 2 to as low as 1 in 5 messages lost).


  • Mario

    #2
    Re: Returning UDP traffic in real-time and control latency

    Hi Wayne,

    I dont know how many stuff are you getting and if it possible to handle it
    by a vb.net windows application... but we can try. You posted the console
    version :-( and what we need is the windows version, where the bug or
    problem is. Any way, I suggest 3 hacks:

    First trick is not up update for every packet! Update only for every half second.
    Cache the results until a Timer fires, and then flush the cache into a control.

    Second trick is to use a StringBuilder for caching, not a string.

    Third trick is to .BeginUpdate .EndUpdate your control (eg. ListBox).

    Here is a sample (with a RichTextBox... add it to the form):


    ' Declare at module level
    Private sb As New System.Text.Str ingBuilder

    ' start the timer
    With Timer1
    .Interval = 500
    .Enabled = getData
    End With
    While getData = True
    Dim data(1024) As Byte
    Dim recv As Integer
    recv = s.ReceiveFrom(d ata, ep)
    Dim strData As String
    strData = System.Text.Enc oding.ASCII.Get String(data, 0, recv)
    ' Add data to cache
    sb.Append(strDa ta & vbCrLf)
    End While
    ' stop the timer
    Timer1.Enabled = False


    Private Sub Timer1_Tick(ByV al sender As System.Object, _
    ByVal e As System.EventArg s) Handles Timer1.Tick
    ' flush cache
    RichTextBox1.Ap pendText(sb.ToS tring)
    ' clear cache
    sb.Remove(0, sb.Length)
    End Sub


    Hope this helps.
    Best regards,
    Mario


    "Wayne M J" <not@home.nor.b igpuddle.com> wrote in message news:uwPej118DH A.3880@TK2MSFTN GP11.phx.gbl...[color=blue]
    > I am capturing syslogd traffic from a firewall/router, if I display the
    > results to Console it runs fine and dandy, but the minute I need it to go to
    > a ListBox, DataGrid or even a text box problems begin to arise.
    >
    > It comes down to what looks like latency, but the control are not fast
    > enough to refresh in time to display all of the packet contents.
    >
    > I have tried threading the function, but that only increases the latency.
    > At one point I seriously thought it was my code:
    > While True
    > Dim data(1024) As Byte
    > Dim recv As Integer
    > recv = s.ReceiveFrom(d ata, ep)
    > 'iep = ep '*** Only needed to get the source of the traffic ***
    > Dim strData As String = System.Text.Enc oding.ASCII.Get String(data, 0,
    > recv)
    > Console.WriteLi ne(strData)
    > End While
    >
    > That is the business end of the code, and there is not much tweaking there
    > that can be done to speed up returns.
    >
    > I have tried this code on a P4, a P3 and an old P2 with the same results,
    > the controls just did not refresh fast enough such that the next line of
    > traffic could be added.
    >
    > I have compiled the code in both Debug (very bad latency about 2 messages in
    > 3 were lost) and Release (1 in 2 to as low as 1 in 5 messages lost).
    >
    >[/color]

    Comment

    • Wayne M J

      #3
      Re: Returning UDP traffic in real-time and control latency

      Thanks for the reply (and sorry for the delay in response).

      I ended up solving the problem, by doing nothing more than upgrading from
      VS.Net2002 to VS.Net2003.

      This is something that I have noticed quite a lot lately, that any code that
      I wrote under 2002 suffers from latency whilst the 2003 code runs perfectly.


      Comment

      Working...