有一部分看不懂,不知道是什么意思
SERVER界面部分是一个FORM 上面只有一个WINSOCK控件,没其他的东西
程序代码如下:
Private Sub Form_Load()
ReDim blnArray(0)
'set Local Port
Winsock1(0).LocalPort = 10101 'This is the port the server listens on
'Listen
Winsock1(0).Listen
blnArray(0) = True
End Sub
Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)
'Check if any free sockets
If Winsock1.Count <> 1 Then
For i = 1 To Winsock1.Count - 1
If blnArray(i) = False Then 'Checks if the socket at index "i" is available
Winsock1(i).Accept requestID 'Accepted connection to old but available socket
Exit Sub
End If
Next i
End If
'Only runs if no open sockets
'Increase size of blnArray
ReDim Preserve blnArray(Winsock1.UBound + 1)
'Load new Winsock1
Load Winsock1(Winsock1.UBound + 1)
'Accept Connection to newly created socket
Winsock1(Winsock1.UBound).Accept requestID
'Updates the Array at requested position to true stating socket is in use at theis index
blnArray(Winsock1.UBound) = True
'Do not worry your new Winsock1 control automatically is given an open port by the Windows OS
End Sub
Private Sub Winsock1_Close(Index As Integer)
SafeClose (Index)
End Sub
Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim strData As String
Dim i As Integer
'get data from client
Winsock1(Index).GetData strData
'Send the data to all connected clients
If LCase(strData) = "/quit" Then
'Closes the connection at index of requested user
SafeClose (Index)
Else
For i = LBound(blnArray) To UBound(blnArray)
SafeSend i, strData
Next i
End If
End Sub
Private Sub Winsock1_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)
'Closes the connection at the errored index
SafeClose (Index)
End Sub
Private Sub SafeSend(Index As Integer, ByVal strData As String)
If Winsock1(Index).State = sckConnected Then
Winsock1(Index).SendData strData
End If
End Sub
Private Sub SafeClose(Index As Integer)
If Winsock1(Index).State = sckConnected Then
blnArray(Index) = False
Winsock1(Index).Close
Unload Winsock1(Index)
End If
End Sub
本人看的似懂非懂,请高手最好能够详细解释一下这个程序,特别是
其中在Winsock1_ConnectionRequest 这个事件里面的部分
如果说明的够清楚的话,加50分,不吝啬!
首先我不知道 声明的 ReDim blnArray(0) 是代表什么意思
Winsock1.Count 查了半天网上也找不到到底代表啥?
找不到资料
If Winsock1.Count <> 1 Then
For i = 1 To Winsock1.Count - 1
If blnArray(i) = False Then 'Checks if the socket at index "i" is available
Winsock1(i).Accept requestID 'Accepted connection to old but available socket
这段最让我头痛,搞的我下面看不下去