Results 1 to 3 of 3

Thread: VB.net UDP

  1. #1

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    VB.net UDP

    I cant find ANY thing on UDP help for vb.net. The .recieve method is always blocking, and I never get a response back. The only things on this forum are posts like "If you searched you could find an example posted a million times!" however the sample doesnt exist!

    ANY help on a UDP packet to an IP address is greatly appreciated.

  2. #2

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: VB.net UDP

    Anybody? I havent found a single UDP sample that works anywhere yet.

  3. #3
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Houston, TX
    Posts
    342

    Re: VB.net UDP

    The receive method is always blocking so you will either want to use the BeginReceive method or thread the Receive method.

    Here is an example using threading...

    VB Code:
    1. Module Module1
    2.  
    3.     Delegate Sub dDataReceived(ByVal Data As String)
    4.  
    5.     Sub Main()
    6.  
    7.         Dim UDPWorker As New Worker
    8.         Dim tWorker As New Threading.Thread(AddressOf UDPWorker.Start)
    9.  
    10.         tWorker.Start()
    11.  
    12.         Console.WriteLine("UDP Client is listening...Press Enter to exit.")
    13.         Console.ReadLine()
    14.  
    15.         UDPWorker.Active = False
    16.         End
    17.  
    18.     End Sub
    19.  
    20.  
    21.  
    22. End Module
    23.  
    24.  
    25. Public Class Worker
    26.     Public Active As Boolean = True
    27.  
    28.     Private udpClient As New Net.Sockets.UdpClient(9999)
    29.  
    30.     Public Sub Start()
    31.  
    32.         Do While Active
    33.             Dim Data() As Byte = udpClient.Receive(New Net.IPEndPoint(Net.IPAddress.Any, 0))
    34.             Console.WriteLine(Text.Encoding.UTF8.GetString(Data))
    35.         Loop
    36.  
    37.     End Sub
    38. End Class

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