一客户端多服务端UDP本地连接代码(同时发送)

Option Explicit
Dim i
Private Sub Form_Load()
    winsockclient.RemoteHost = "127.0.0.1"
    winsockserver1(0).RemoteHost = "127.0.0.1"
    winsockserver1(0).RemotePort = "1002"
    winsockserver1(0).Bind 1001
    winsockserver1(1).RemoteHost = "127.0.0.1"
    winsockserver1(1).RemotePort = "1002"
    winsockserver1(1).Bind 1003
    winsockserver1(2).RemoteHost = "127.0.0.1"
    winsockserver1(2).RemotePort = "1002"
    winsockserver1(2).Bind 1004
End Sub

Private Sub Text1_Change()
    winsockclient.RemoteHost = "127.0.0.1"
    winsockclient.RemotePort = 1001
    winsockclient.SendData Text1.Text
    winsockclient.RemoteHost = "127.0.0.1"
    winsockclient.RemotePort = 1003
    winsockclient.SendData Text1.Text
    winsockclient.RemoteHost = "127.0.0.1"
    winsockclient.RemotePort = 1004
    winsockclient.SendData Text1.Text
End Sub

Private Sub Text2_Change(Index As Integer)
winsockserver1(Index).SendData Text2(Index).Text
End Sub

Private Sub winsockclient_DataArrival(ByVal bytesTotal As Long)
Dim strdate As String
    winsockclient.GetData strdate
    Text1.Text = strdate
End Sub

Private Sub winsockserver1_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim strdate As String
    winsockserver1(Index).GetData strdate
    Text2(Index).Text = strdate
End Sub

 

你可能感兴趣的:(一客户端多服务端UDP本地连接代码(同时发送))