使用Winsock控件在服务器端接受多个请求为什么出问题:
服务器端代码如下Private intMax As LongPrivate Sub cmdSend_Click()Dim Max As Integer
Max = intMax'''下面的程序得不到预期的结果,不能在多个客户端收到来自服务器的信息'''''''
Do While Max > 0
If tcpServer(Max).State = 7 Then tcpServer(Max).SendData
Max = Max - 1
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
LoopEnd SubPrivate Sub Form_Load() intMax = 0 tcpServer(0).LocalPort = 1001
tcpServer(0).ListenfrmClient.Show
frmClient01.ShowEnd SubPrivate Sub tcpServer_ConnectionRequest(Index As Integer, ByVal requestID As Long)If tcpServer(0).State <> sckClosed Then _
tcpServer(0).Close If Index = 0 Then _
intMax = intMax + 1
Load tcpServer(intMax)
tcpServer(intMax).LocalPort = 0
tcpServer(intMax).Accept requestID
Label1.Caption = "Client " + CStr(intMax) + " Connect"
End Sub
服务器端代码如下Private intMax As LongPrivate Sub cmdSend_Click()Dim Max As Integer
Max = intMax'''下面的程序得不到预期的结果,不能在多个客户端收到来自服务器的信息'''''''
Do While Max > 0
If tcpServer(Max).State = 7 Then tcpServer(Max).SendData
Max = Max - 1
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
LoopEnd SubPrivate Sub Form_Load() intMax = 0 tcpServer(0).LocalPort = 1001
tcpServer(0).ListenfrmClient.Show
frmClient01.ShowEnd SubPrivate Sub tcpServer_ConnectionRequest(Index As Integer, ByVal requestID As Long)If tcpServer(0).State <> sckClosed Then _
tcpServer(0).Close If Index = 0 Then _
intMax = intMax + 1
Load tcpServer(intMax)
tcpServer(intMax).LocalPort = 0
tcpServer(intMax).Accept requestID
Label1.Caption = "Client " + CStr(intMax) + " Connect"
End Sub
If tcpServer(Max).State = 7 Then
tcpServer(Max).SendData
DoEvents
End If