Results 1 to 2 of 2

Thread: some udp help

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Location
    Bentonville, AR
    Posts
    22

    some udp help

    Hi,

    I have a piece of software running on a linux box that is transmitting information every few minutes over UDP to a destination port of 3052. After looking at a packet sniffer, the data is making it to the computer that I am having problems with.

    I need to create a program that will listen on port 3052 and receive that data. I have tried for several hours to find source code to listen only, but i'm having little luck with that. I am using VB .net 2005.

    thanks,

    cory

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: some udp help

    The MSDN help topic for the UdpClient.BeginReceive method has a code example of basically what you want. It's in C# only, but here's a translation courtesy of Instant VB:
    vb Code:
    1. Public Shared messageReceived As Boolean = False
    2.  
    3. Public Shared Sub ReceiveCallback(ByVal ar As IAsyncResult)
    4.   Dim u As UdpClient = CType((CType(ar.AsyncState, UdpState)).u, UdpClient)
    5.   Dim e As IPEndPoint = CType((CType(ar.AsyncState, UdpState)).e, IPEndPoint)
    6.  
    7.   Dim receiveBytes As Byte() = u.EndReceive(ar, e)
    8.   Dim receiveString As String = Encoding.ASCII.GetString(receiveBytes)
    9.  
    10.   Console.WriteLine("Received: {0}", receiveString)
    11.   messageReceived = True
    12. End Sub
    13.  
    14. Public Shared Sub ReceiveMessages()
    15.   ' Receive a message and write it to the console.
    16.   Dim e As IPEndPoint = New IPEndPoint(IPAddress.Any, listenPort)
    17.   Dim u As UdpClient = New UdpClient(e)
    18.  
    19.   Dim s As UdpState = New UdpState()
    20.   s.e = e
    21.   s.u = u
    22.  
    23.   Console.WriteLine("listening for messages")
    24.   u.BeginReceive(New AsyncCallback(AddressOf ReceiveCallback), s)
    25.  
    26.   ' Do some work while we wait for a message. For this example,
    27.   ' we'll just sleep
    28.   Do While Not messageReceived
    29.     Thread.Sleep(100)
    30.   Loop
    31. End Sub
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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