结构如下:一个服务端两个客户端,用两个客户端分别向服务端发送数据,服务端都能接收成功,可是用服务端向客户端发送数据时,不能发送成功。服务端源码如下:
Option Explicit
Private intMax As LongPrivate Sub Command1_Click()
  '向下发送数据
  Dim i As Integer
    For i = 1 To intMax
      If tcpServer(i).State <> sckClosed Then
        tcpServer(i).SendData "测试" & Text1.Text & i
      End If
    Next i
End SubPrivate Sub Command2_Click()
    client.Show
    client2.Show
End SubPrivate Sub Form_Load()
    intMax = 0
    '进行侦听
    tcpServer(0).Protocol = sckTCPProtocol
    tcpServer(0).LocalPort = 1234
    tcpServer(0).Listen
    
    '打开客户端
    client.Show
    client2.Show
End Sub
Private Sub tcpserver_Close(index As Integer)
    If tcpServer(0).State <> 0 Then tcpServer(0).Close
    tcpServer(0).Protocol = sckTCPProtocol
    tcpServer(0).LocalPort = 1234
    tcpServer(0).Listen
End SubPrivate Sub tcpserver_ConnectionRequest(index As Integer, ByVal requestID As Long)
    If index = 0 Then
      intMax = intMax + 1
      Load tcpServer(intMax)
      tcpServer(intMax).LocalPort = 1234 + intMax
      tcpServer(intMax).Accept requestID
   End If
End SubPrivate Sub tcpserver_DataArrival(index As Integer, ByVal bytesTotal As Long)
    Dim str As String
    tcpServer(index).GetData str
    Text1.Text = str
End Sub