vb.net用UDP协议进行通讯的代码示例
'xiansr.2014/2/7 vb.net2010 调试bai通过 Imports System.Net Imports System.Net.Sockets Imports System.Text Public Class Form1 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Dim udpClient As New UdpClient(11000) Try udpClient.Connect("127.0.0.1", 11000) Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(RichTextBox1.Text) udpClient.Send(sendBytes, sendBytes.Length) Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0) Dim receiveBytes As [Byte]() = udpClient.Receive(RemoteIpEndPoint) Dim returnData As String = Encoding.ASCII.GetString(receiveBytes) RichTextBox2.Text = "接收到: " + returnData.ToString() 'Debug.Print(("This message was sent from " + RemoteIpEndPoint.Address.ToString() + " on their port number " + RemoteIpEndPoint.Port.ToString())) udpClient.Close() Catch ex As Exception stop End Try End Sub End Class
运营不易,
感谢支持!
我的微信
我的微信公众号
我的微信公众号扫一扫
我的公众号