跪求大神指点 VB.net 的UdpClient 收到文字信息时候显示?号,求大神指点怎么转换成汉字?
ImportsSystem.NetImportsSystem.Net.SocketsImportsSystem.TextPublicClassForm1PrivateSu...
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 qidongxianc = New Threading.Thread(AddressOf qd)
qidongxianc.Start()
End Sub
Sub qd()
Dim UdpClient1 = New UdpClient(11000)
Do
Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
Dim receiveBytes As [Byte]() = UdpClient1.Receive(RemoteIpEndPoint)
Dim returnData As String = Encoding.ASCII.GetString(receiveBytes)
MsgBox(returnData.ToString())
Loop
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim UdpClient2 As New UdpClient()
UdpClient2.Connect("127.0.0.1", 11000)
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("我是文字")
UdpClient2.Send(sendBytes, sendBytes.Length)
End Sub
End Class 展开
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 qidongxianc = New Threading.Thread(AddressOf qd)
qidongxianc.Start()
End Sub
Sub qd()
Dim UdpClient1 = New UdpClient(11000)
Do
Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
Dim receiveBytes As [Byte]() = UdpClient1.Receive(RemoteIpEndPoint)
Dim returnData As String = Encoding.ASCII.GetString(receiveBytes)
MsgBox(returnData.ToString())
Loop
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim UdpClient2 As New UdpClient()
UdpClient2.Connect("127.0.0.1", 11000)
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("我是文字")
UdpClient2.Send(sendBytes, sendBytes.Length)
End Sub
End Class 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询