vb.net UDP 本地发送和接收怎么使用同一个端口呢 60
用vb.net做个小工具,UDP发送到服务器并接收返回的数据。本地怎么发送和接收都用同一个端口呢?因为服务器会把数据返回到这个端口上。设置发送和接收同一个端口,会提示出错...
用vb.net做个小工具,UDP发送到服务器并接收返回的数据。
本地怎么发送和接收都用同一个端口呢?因为服务器会把数据返回到这个端口上。
设置发送和接收同一个端口,会提示出错,每个套接字地址只允许使用一次。
以前vb的时候DataArrival就直接接收了,vb.net怎么弄呢??
有参考程序最好···有效当加分
这是我现在的·
Imports System.Net
Imports System.Text.Encoding
Public Class Form1
Dim publisher As New Sockets.UdpClient(0)
Dim subscriber As New Sockets.UdpClient(2000)
Private Sub Timer1_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Try
Dim ep As IPEndPoint = New IPEndPoint(IPAddress.Any, 0)
Dim rcvbytes() As Byte = subscriber.Receive(ep)
TextBox4.Text = TextBox4.Text & ASCII.GetString(rcvbytes) '接收到TextBox4
Catch ex As Exception
End Try
End Sub
Private Sub Form1_Load_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
subscriber.Client.ReceiveTimeout = 100
subscriber.Client.Blocking = False
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
publisher.Connect(TextBox1.Text, TextBox2.Text) '指定连接到IP 端口
Dim sendbytes() As Byte = ASCII.GetBytes(TextBox3.Text) '发送TextBox3内容
publisher.Send(sendbytes, sendbytes.Length)
End Sub
End Class 展开
本地怎么发送和接收都用同一个端口呢?因为服务器会把数据返回到这个端口上。
设置发送和接收同一个端口,会提示出错,每个套接字地址只允许使用一次。
以前vb的时候DataArrival就直接接收了,vb.net怎么弄呢??
有参考程序最好···有效当加分
这是我现在的·
Imports System.Net
Imports System.Text.Encoding
Public Class Form1
Dim publisher As New Sockets.UdpClient(0)
Dim subscriber As New Sockets.UdpClient(2000)
Private Sub Timer1_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Try
Dim ep As IPEndPoint = New IPEndPoint(IPAddress.Any, 0)
Dim rcvbytes() As Byte = subscriber.Receive(ep)
TextBox4.Text = TextBox4.Text & ASCII.GetString(rcvbytes) '接收到TextBox4
Catch ex As Exception
End Try
End Sub
Private Sub Form1_Load_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
subscriber.Client.ReceiveTimeout = 100
subscriber.Client.Blocking = False
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
publisher.Connect(TextBox1.Text, TextBox2.Text) '指定连接到IP 端口
Dim sendbytes() As Byte = ASCII.GetBytes(TextBox3.Text) '发送TextBox3内容
publisher.Send(sendbytes, sendbytes.Length)
End Sub
End Class 展开
1个回答
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是一家国内优质海外HTTP代理商,拥有一个庞大的IP资源池,覆盖200多个地区,IP数量大且匿名度高。其优点还包括超高并发、稳定高效、技术服务等特点,同时提供HTTP、HTTPS以及SOCKS5协议支持。此外,Sto...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询