怎么用VB winsock(UDP协议)进行发送字符串?(急急急)

2024-12-05 03:48:01
推荐回答(4个)
回答1:

发送端:
Private Sub Command1_Click()
Winsock1.SendData Text1.Text
End Sub

Private Sub Form_Load()
Form1.Caption = "发送端"
Text1.Text = ""
Command1.Caption = "发送"
Winsock1.LocalPort = 1000
Winsock1.RemotePort = 1001
Winsock1.RemoteHost = 【对方IP】
Winsock1.Protocol = sckUDPProtocol
Winsock1.Bind 1000, Winsock1.LocalIP
End Sub
接收端:
Private Sub Form_Load()
Form1.Caption = "接收端"
Text2.Text = ""
Winsock2.LocalPort = 1001
Winsock2.RemotePort = 1000
Winsock2.RemoteHost = 【你的IP】
Winsock2.Protocol = sckUDPProtocol
Winsock2.Bind 1001, Winsock2.LocalIP
End Sub

Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long)
Dim a As String
Winsock2.GetData a, vbString
Text2.Text = a
End Sub

回答2:

我是打酱油的。。。。。。。。。。。

回答3:

 

回答4:

网上去找吧,代码一大堆,源码直接就有的