【问题标题】:send updated client list to all connected clients向所有连接的客户端发送更新的客户端列表
【发布时间】:2013-08-31 17:05:55
【问题描述】:

嗯,我有这个代码用于我的服务器连接请求。

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

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

【问题讨论】:

  • 既然你已经发送它(据我从你发布的代码中可以看出)......我假设你问的是一个完全不同的问题。您是否使用短语“发送到”来表示“显示在”组合框或其他内容?
  • 哦,是的,我就是这个意思。将客户端列表显示到所有已连接客户端的组合框。

标签: vb6 winsock


【解决方案1】:

如果我正确理解了您的代码,(并且基于 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-04
    • 1970-01-01
    • 2014-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-19
    • 1970-01-01
    相关资源
    最近更新 更多