这是服务器端代码,想用服务器端一直可以监听接收多个客户端的指令,就用了一个winSock数组,我是参照MSDN里的弄的,大家看看这个ConnectionRequest函数有什么问题没有?
还请大家对我要实现的这个功能多提些建议,多提供些示例,谢谢
Option ExplicitPrivate intMax As LongPrivate Sub Form_Load()
   intMax = 0
   sckServer(0).Listen
End SubPrivate Sub sckServer_ConnectionRequest(Index As Integer, ByVal requestID As Long)
   If Index = 0 Then
      intMax = intMax + 1
      Load sckServer(intMax)
      sckServer(intMax).LocalPort = 7611
      If sckServer(intMax).State <> sckClosed Then
        sckServer(intMax).Close
      End If
      sckServer(intMax).Accept requestID
   End If
End Sub

解决方案 »

  1.   

    运行这段代码时出错了,哎,
    为什么不管哪个电脑运行了客户端,这个index都是0呀
      

  2.   

    因为0是用来侦听的.要是把0接受连接了,那谁来侦听??呵呵~
    intMax = intMax + 1
    Load sckServer(intMax)
    看到这两句吗?当有新连接请求,intMax就 + 1.然后加载一个新的实例来接受连接!0就继续回去做侦听工作了!依此类推...就能做到接受多个连接了
      

  3.   

    Option ExplicitPrivate intMax As LongPrivate Sub Form_Load()
       intMax = 0
    sckServer(intMax).LocalPort = 7611
          ‘写这里,写下面会出错
       sckServer(0).Listen
    End SubPrivate Sub sckServer_ConnectionRequest(Index As Integer, ByVal requestID As Long)
       If Index = 0 Then
          intMax = intMax + 1
          Load sckServer(intMax)
          If sckServer(intMax).State <> sckClosed Then
            sckServer(intMax).Close
          End If
          sckServer(intMax).Accept requestID
       End If
    End Sub
      

  4.   

    Load sckServer(intMax)
         sckServer(intMax).LocalPort = 7611
    这里会出错,你没LOAD一个SOCKS都指定相同的PORT,会冲突的,这个PORT还是不指定由计算机自动获得的更好,并且你这里intMax是自增的,最好是做个循环在一个MAX上限里寻找没使用的SOCKS()然后使用这个来建立连接,否则在断开的时候你虽然释放了该控件,但下次连接的时候本控件将无法再次使用,intMax会越来越大的
      

  5.   

    http://community.csdn.net/Expert/topic/3652/3652431.xml?temp=.4773218
    试试这个