Mega Code Archive
UdpClient Class provides User Datagram Protocol (UDP) network services
Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Public Class MainClass
Shared Sub Main()
Dim udpClient As New UdpClient(11000)
Try
udpClient.Connect("www.domain.com", 11000)
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("Is anybody there?")
udpClient.Send(sendBytes, sendBytes.Length)
Dim udpClientB As New UdpClient()
udpClientB.Send(sendBytes, sendBytes.Length, "AlternateHostMachineName", 11000)
Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
Dim receiveBytes As [Byte]() = udpClient.Receive(RemoteIpEndPoint)
Dim returnData As String = Encoding.ASCII.GetString(receiveBytes)
Console.WriteLine(returnData.ToString())
Console.WriteLine(RemoteIpEndPoint.Address.ToString())
Console.WriteLine(RemoteIpEndPoint.Port.ToString())
udpClient.Close()
udpClientB.Close()
Catch e As Exception
Console.WriteLine(e.ToString())
End Try
End Sub
End Class