当前位置:编程学习 > VB >>

救命!为什么这个Winsock出现实时错误?

代码如下:
Option Explicit
Dim Connections As Integer
Dim Strdata As String
Dim Index As Integer
Dim conlab As Integer
Dim findget As String
Dim spc2 As String
Dim Page As String
Dim Nr As String
Dim Tx As String
Dim Lg As String
Dim Tx1 As String
Dim m As Integer
Dim max As Integer

Private Sub Command1_Click()
Connections = 100
Me.Winsock1.Close
Me.Winsock1.LocalPort = 8080
Me.Winsock1.Listen
List1.AddItem Time & "服务器开始运行"
End Sub

Private Sub Command2_Click()
Me.Winsock1.Close
Me.List1.AddItem Time & "服务器已停止运行"
End Sub

Private Sub Command3_Click()
Me.Hide
End Sub

Private Sub Command4_Click()
Unload Me
End Sub

Private Sub Form_Load()
Dim I As Integer
max = 100
Winsock1.Close
Winsock1.LocalPort = 8080
Winsock1.Listen
For I = 1 To max
Load Winsock1
Next
Me.Show
Me.WebPfad = App.Path & "\"
End Sub


Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Dim I As Integer
For I = 1 To max
If Winsock1.State = sckClosed Then
Winsock1.Accept requestID
End If
Next
Ip Strdata, Index, "Connect"
If Index = 0 Then
Connections = Connections + 1
conlab = conlab + 1
Load Winsock1
Winsock1.LocalPort = 0
Winsock1.Accept requestID
End If
End Sub

Private Sub Ip(GetD, Index, ConnectD)
If ConnectD = "Connect" Then
Me.List1.AddItem ConnectD & " " & Time & " " & Winsock1.RemoteHostIP
Else
Me.List1.AddItem ConnectD & " " & Time & " " & Winsock1.RemoteHostIP
End If
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim Strdata As String
Winsock1.GetData Strdata
If Mid$(Strdata, 1, 3) = "GET" Then
findget = InStr(Strdata, "GET")
spc2 = InStr(findget + 5, Strdata, "")
Page = Mid$(Strdata, findget + 5, spc2 - (findget + 4))
Ip Strdata, Index, "Asked For" & Page
SendPage Page, Index
End If
End Sub

Public Sub SendPage(Page, Index)
On Error GoTo Fehler
If Page = "" Then Page = "index.html"
Nr = FreeFile
Tx = ""
Lg = FileLen(WebPfad & Page)
Open WebPfad & Page For Binary As Nr
Tx1 = ""
For m = 1 To Lg
Get #Nr, , Tx
Tx1 = Tx1 + Tx
Next
Close Nr
Winsock1.SendData Tx1
Fehler: If Err.Number = 53 Then Winsock1.SendData "您所访问的页面不存在!"

End Sub

急啊……明天就要用啦!
--------------------编程问答-------------------- 嘿嘿,我又来啦!!!!!!
你之前的一个帖子中我回答过了(回答过两次,参考第二次的回答)
把Winsock1设置成数组,即修改它的Index属性!
Load函数使用不正常导致 --------------------编程问答-------------------- 就是一楼说的问题
Private Sub winsk1_ConnectionRequest(index As Integer, ByVal requestID As Long) '
On Error GoTo err
If index = 0 Then
    Dim i As Integer
    Dim bFoundClosed As Boolean
    bFoundClosed = False
    For i = 1 To intMax1
        If Winsk1(i).State = sckClosed Then
            bFoundClosed = True
            Exit For
        End If
    Next
     If bFoundClosed Then
         Winsk1(i).LocalPort = Port
         Winsk1(i).Accept requestID
     Else
         Y_intMax = Y_intMax + 1
         Load Winsk1(Y_intMax)
         Winsk1(Y_intMax).LocalPort = Port
         Winsk1(Y_intMax).Accept requestID
    End If
End If
Y_ReIP = Winsk1(Y_intMax).RemoteHostIP
err:
    Exit Sub
End Sub --------------------编程问答-------------------- 不知,帮顶
补充:VB ,  网络编程
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,