0

好吧,我有我的服务器连接请求的代码。

If sckClients(clientCounter).State <> adstateclosed Then sckClients(clientCounter).Close        
sckClients(clientCounter).Accept requestID
Command1.Enabled = True
MsgBox "Connected to client."
Combo1.AddItem sckClients(clientCounter).LocalIP & "(" & clientCounter & ")"
clientCounter = clientCounter + 1
Load sckClients(clientCounter)

这是为了更新客户列表。

StrMsg = "1~Server~"
For x = 0 To Combo1.ListCount - 1
    If x = Combo1.ListCount - 1 Then
        StrMsg = StrMsg & Combo1.List(x)
    Else
        StrMsg = StrMsg & Combo1.List(x) & "~"
    End If
Next x


For x = 0 To clientCounter - 1
    sckClients(x).SendData StrMsg
Next x

我的问题是,如何将其发送到每个客户的组合框客户列表?

4

1 回答 1

0

如果我正确理解了您的代码(并且基于 Bob77 的说明),您发送给连接客户端的消息可能是这样的:

"1~Server~192.168.0.101(0)~69.125.83.76(1)~127.0.0.1(2)"

然后你只需要使用 VB6 的split函数来获取这样的信息:

在客户端(伪代码):

Private Sub WinSock_OnData(...)
    Dim Buffer As String
    Dim BufferArray() As String
    Dim Index As Long

    Call WinSock.GetData(Buffer, ...)        
    BufferArray = Split(Buffer, "~")

    If BufferArray(0) = "1" Then
        Call ComboxBox1.Clear        
        For Index = 1 To Ubound(BufferArray)
            Call ComboxBox1.AddItem(BufferArray(Index))
        Next Index
    End If

End Sub
于 2014-02-02T06:38:48.780 回答