vb.net用UDP协议进行通讯的代码示例

编程评论阅读模式

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

继续阅读
weinxin
我的微信
运营不易,
感谢支持!
公式库网
  • 本文由 发表于 2021年1月20日 16:37:24
  • 转载请务必保留本文链接:https://www.gongshiku.com/html/202101/vb-netyongudpxieyijinxingtongxundedaimashili.html
Python学习

Python操作pymysql详细示例

Python操作pymysql详细示例 程序在运行时,数据都是在内存中的。当程序终止时,通常需要将数据保存在磁盘上。前面我们有学过将数据写入文件就是保存到磁盘的一种方式。但是当面对大批量的数据时,为...

发表评论