本文整理汇总了VB.NET中System.Net.Sockets.UdpClient.Receive方法的典型用法代码示例。如果您正苦于以下问题:VB.NET UdpClient.Receive方法的具体用法?VB.NET UdpClient.Receive怎么用?VB.NET UdpClient.Receive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Sockets.UdpClient
的用法示例。
在下文中一共展示了UdpClient.Receive方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: UdpClient
'Creates a UdpClient for reading incoming data.
Dim receivingUdpClient As New UdpClient(11000)
'Creates an IPEndPoint to record the IP address and port number of the sender.
' The IPEndPoint will allow you to read datagrams sent from any source.
Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
Try
' Blocks until a message returns on this socket from a remote host.
Dim receiveBytes As [Byte]() = receivingUdpClient.Receive(RemoteIpEndPoint)
Dim returnData As String = Encoding.ASCII.GetString(receiveBytes)
Console.WriteLine(("This is the message you received " + returnData.ToString()))
Console.WriteLine(("This message was sent from " + RemoteIpEndPoint.Address.ToString() + " on their port number " + RemoteIpEndPoint.Port.ToString()))
Catch e As Exception
Console.WriteLine(e.ToString())
End Try
End Sub
示例2: Tester
' 导入命名空间
Imports System
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Public Class Tester
Public Shared Sub Main
Dim MyIP As IPAddress
Dim bytes(200) As Byte
Dim Port1 As Integer = 8080
Dim port2 As Integer = 3128
MyIP = IPAddress.Parse("166.111.175.81")
Dim myLocal As New IPEndPoint(MyIP, Port1)
Dim myRemote As New IPEndPoint(MyIP, port2)
Dim receive1 As New UdpClient(myRemote)
Dim send1 As New UdpClient(myLocal)
Try
bytes = System.Text.Encoding.ASCII.GetBytes("AAA")
send1.Send(bytes, bytes.Length, myRemote)
receive1.Receive(myLocal)
Catch ex As Exception
Console.WriteLine("Error")
End Try
send1.Close()
receive1.Close()
End Sub
End Class