我用WINSOCK控件数组,收发数据,但是当达到一定数量后,随机,说不准什么时候就会端口死掉!!连接不上,请高手看看这是怎么回事!!代码是否有问题!!!!!!!!!Private Sub w1_Close(Index As Integer)
'MsgBox "w1.close"
'w1(intmax1).Close
'Unload w1(intmax1)
Label18.Caption = "已经关闭第" & Index & "个端口"
Text3.Text = "端口正常关闭状态:重新监听中"
w1(Index).Close
w1(Index).LocalPort = 0
w1(Index).Listen
End SubPrivate Sub w1_ConnectionRequest(Index As Integer, ByVal requestID As Long)If Index = 0 Then
intmax1 = intmax1 + 1
Label18.Caption = "已经打开端口第" & intmax1 & "个"
Load w1(intmax1)
      w1(intmax1).LocalPort = 0
      w1(intmax1).Accept requestIDText3.Text = "IP:" + w1(intmax1).RemoteHostIP + "请求建立连接中"
      End If
If i = 1 Then
Text1.Text = Text1.Text & vbCrLf & "IP:" & w1(intmax1).RemoteHostIP & " " & Date & " " & Time & " 端口号:" & w1(intmax1).RemotePort & "建立连接"Else
End Ifcishu = cishu + 1
Label4.Caption = "到目前为止连接用户数量:" & cishu
If text2_text = "" Then
w1(intmax1).Close
Text3.Text = "端口无数据发送状态:关闭重新监听中 IP:" + w1(intmax1).RemoteHostIP + "已建立完连接"""
GoTo over
Else
w1(intmax1).SendData text2_text
Text3.Text = "端口数据已发送:关闭重新监听中 IP:" + w1(intmax1).RemoteHostIP + "已建立完连接"""
End If
over:
End SubPrivate Sub w1_DataArrival(Index As Integer, ByVal bytesTotal As Long)
w1(Index).SendData "拒绝接收"
End SubPrivate Sub w1_Error(Index As Integer, ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
w1(Index).Close
w1(Index).LocalPort = 0
w1(Index).ListenText3.Text = "端口错误状态:复位重新监听中"
End SubPrivate Sub w1_SendComplete(Index As Integer)
'MsgBox "发送成功"
If list_index = 1 Then
List1.AddItem "发送数据给:" & w1(Index).RemoteHostIP & "  端口:" & w1(Index).RemotePort & "完毕"
Else
End If
w1(Index).CloseEnd Sub

解决方案 »

  1.   

    你到底是用哪个Winsock在监听?关闭的又是哪个Winsock? 你的程序运行以后应该有很多端口都在监听吧?
      

  2.   

    监听就一个,
    w1(0).LocalPort = "8888"
    w1(0).Listen
      

  3.   

    If Index = 0 Then
    intmax1 = intmax1 + 1
    Label18.Caption = "已经打开端口第" & intmax1 & "个"
    Load w1(intmax1)
          w1(intmax1).LocalPort = 0
          w1(intmax1).Accept requestID
    你死掉的时候看看端口是不是32767
      

  4.   

    这时用telnet 218.87.140.69 8888 监听端口是关闭的!影子再帮我看看代码有没有问题啊!!
      

  5.   

    代码不全,不能接受端口的主要原因是对winsock(0)进行操作了,查下你的其他代码
      

  6.   

    Option Explicit
    Private intMax As Long 'winsock最大的下标Private Sub Form_Load()
        intMax = 0
        Winsock1(0).LocalPort = 7699 '本地监听的端口
        Winsock1(0).ListenEnd Sub
    '*************************************************************************
    '**函 数 名:Winsock1_ConnectionRequest
    '**输    入:Index(Integer)        -
    '**        :ByVal requestID(Long) -
    '**输    出:无
    '**功能描述:对方请求连接时候触发,当没有以前已经关闭的控件的winsock控件数组的话就创建
    '**全局变量:
    '**调用模块:
    '**作    者:影子
    '**日    期:2005-02-06 08:39:12
    '**修 改 人:
    '**日    期:
    '**版    本:V1.0.0
    '*************************************************************************
    Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)    If Index = 0 Then
            Dim i As Integer
            Dim temp As Integer
            temp = 0
            For i = 1 To intMax
                If Winsock1(i).State = 0 Then
                    temp = i
                    Exit For
                End If
            Next
            If temp = 0 Then
                intMax = intMax + 1
                temp = intMax
            End If
            Load Winsock1(temp)        Winsock1(temp).LocalPort = 0        Winsock1(temp).Accept requestID
        End IfEnd Sub
    Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long)
        '获得数据
       ' On Error Resume Next
        Dim clientDat As String
        Winsock1(Index).GetData clientDat, vbString
        If clientDat <> "" Then
            Call fjmsg(clientDat, Index)
        End IfEnd Sub
      

  7.   

    If Index = 0 Then
    intmax1 = intmax1 + 1
    Label18.Caption = "已经打开端口第" & intmax1 & "个"
    Load w1(intmax1)
          w1(intmax1).LocalPort = 0
          w1(intmax1).Accept requestID
      

  8.   

    zyg0(影子(这句代码是做什么用的?
    Call fjmsg(clientDat, Index)
      

  9.   

    zyg0(影子的代码存在错误!!重复加载控件数组!!!For i = 1 To intMax
                If Winsock1(i).State = 0 Then
                    temp = i   '这里如果不加UNLOAD的话那么就会到了下面load就会出错!!!不知道加unload会不会有影响!!请影子出来说明一下
                    Exit For
                End If
            Next
            If temp = 0 Then
                intMax = intMax + 1
                temp = intMax
            End If
            Load Winsock1(temp
      

  10.   

    我搞不清楚你这段代码是什么意思
    Private Sub w1_Close(Index As Integer)
    'MsgBox "w1.close"
    'w1(intmax1).Close
    'Unload w1(intmax1)
    Label18.Caption = "已经关闭第" & Index & "个端口"
    Text3.Text = "端口正常关闭状态:重新监听中"
    w1(Index).Close
    w1(Index).LocalPort = 0
    w1(Index).Listen
    End Sub
    Private Sub w1_Error(Index As Integer, ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
    w1(Index).Close
    w1(Index).LocalPort = 0
    w1(Index).ListenText3.Text = "端口错误状态:复位重新监听中"
    End Sub发生错误或者关闭连接的Winsock关闭,然后监听一闲置端口,如果有很多连接的话,那监听的Winsock也一定很多吧,楼主好强。
      

  11.   

    Call fjmsg(clientDat, Index)
    这句你不用管是我分拣消息的函数,和你没有关系
      

  12.   

    不要unload 但是必须关闭说错了
      

  13.   

    能不能把端口号和winsock数组下标联系上呢》?
      要是winsock(i)关闭,端口i也就关闭了!有新的连接请求的时候我们就去判断哪个端口是空闲  的,相应就load winsock(端口) 控件接受连接!