怎么用VB winsock(UDP协议)进行发送字符串?(急急急)
推荐于2016-07-25
展开全部
发送端:
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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询