vb中Winsock简单连接
1个回答
展开全部
服务端代码:
Private Sub Form_Load()
Winsock1.Protocol = sckUDPProtocol
Winsock1.RemoteHost = "127.0.0.1"
Winsock1.RemotePort = 8765
Winsock1.Bind 5678
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
Winsock1.SendData Text1.Text
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim s As String
Winsock1.GetData s
Text1.Text = s
End Sub
客户端代码:
Private Sub Form_Load()
Winsock1.Protocol = sckUDPProtocol
Winsock1.RemoteHost = "127.0.0.1"
Winsock1.RemotePort = 5678
Winsock1.Bind 8765
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
Winsock1.SendData Text1.Text
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim s As String
Winsock1.GetData s
Text1.Text = s
End Sub
以上代码是用在服务端和客户端在同一台电脑上的情况,如果要在局域网内不同的电脑上进行测试,请把Winsock1.RemoteHost的值改为对方电脑的IP地址或电脑名。
Private Sub Form_Load()
Winsock1.Protocol = sckUDPProtocol
Winsock1.RemoteHost = "127.0.0.1"
Winsock1.RemotePort = 8765
Winsock1.Bind 5678
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
Winsock1.SendData Text1.Text
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim s As String
Winsock1.GetData s
Text1.Text = s
End Sub
客户端代码:
Private Sub Form_Load()
Winsock1.Protocol = sckUDPProtocol
Winsock1.RemoteHost = "127.0.0.1"
Winsock1.RemotePort = 5678
Winsock1.Bind 8765
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
Winsock1.SendData Text1.Text
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim s As String
Winsock1.GetData s
Text1.Text = s
End Sub
以上代码是用在服务端和客户端在同一台电脑上的情况,如果要在局域网内不同的电脑上进行测试,请把Winsock1.RemoteHost的值改为对方电脑的IP地址或电脑名。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询