1,502
社区成员
发帖
与我相关
我的任务
分享
Private Sub Sock_TCP_Close(index As Integer)
'将关闭的连接对应的用户 状态清0 除非已经在线。
Dim elem As stackelem
If index = 0 Then
MsgBox "a"
Else
Unload Sock_TCP(index)
elem.index = index
push elem
End If
With Sock(elem.index)
.index = elem.index
.RequestID = 0
.Connect_IP = ""
End With
End Sub
Private Sub Sock_TCP_ConnectionRequest(index As Integer, ByVal RequestID As Long)
Dim tmp_index As Integer
Dim elem As stackelem
If StackEmpty <> True Then
pop elem
End If
'MsgBox Sock_TCP(0).State
Load Sock_TCP(elem.index)
PRINTMSG "Connection Request!"
If Sock_TCP(elem.index).State <> sckClosed Then
Sock_TCP(elem.index).Close
End If
Sock_TCP(elem.index).Accept RequestID
PRINTMSG "Current Connection Accepted By Sock:" & CStr(elem.index) & "!"
With Sock(elem.index) '11/5 突然觉得这个结构现在没用,,,,
.index = elem.index
.RequestID = RequestID
.Connect_IP = Sock_TCP(elem.index).RemoteHostIP
End With
CountNum = CountNum + 1
PRINTMSG "Current Connection Comes From:" & Sock_TCP(elem.index).RemoteHostIP '为了简单起见放在这 严格上说 这样描述并步正确!
PRINTMSG "Current Connections:" & CStr(CountNum)
End Sub
Attribute VB_Name = "SockStruct"
Public Type Sockets
Index As Integer
RequestID As Long
Connect_IP As String
End Type
Public Type stackelem
Index As Integer
End Type
Public Sock(399) As Sockets
Public stack(399) As stackelem
Public s_top As Integer
Public s_base As Integer
Public Number As Integer
Public stack_empty As stackelem
Public Function StackEmpty() As Boolean
If Number = 0 Then
StackEmpty = True
Else
StackEmpty = False
End If
End Function
Public Function init_stack()
Number = 400
s_top = 400
s_base = 0
For i = 0 To 399
stack(i).Index = i
Next
End Function
Public Function push(elem As stackelem)
'由于只限制400 连接 不会出现三益出
stack(Number) = elem
Number = Number + 1
s_top = Number
End Function
Public Function pop(elem As stackelem)
elem = stack(s_top - 1)
Number = Number - 1
s_top = Number
End Function