我们来自五湖四海,不为别的,只因有共同的爱好,为中国互联网发展出一分力!

vb.net 模拟UDP通信

2014年05月12日00:39 阅读: 33865 次

标签: vb.net 模拟UDP通信

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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 = ASCII.GetString(rcvbytes)
????????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)
????????Dim sendbytes() As Byte = ASCII.GetBytes(TextBox3.Text)
????????publisher.Send(sendbytes, sendbytes.Length)
????End Sub
End Class


?

?

?

\

分享到: 更多
?2019 安全焦点 版权所有.