| fortunataw 2005-01-28, 3:55 pm |
| I have a main application that calls an ActiveX DLL
(prWinsockWrapper.dll) which contains a form with winsock
control and a public class (clsWinsockMain).
The control events are wrapped into the clsWinsockMain.
The main application then instantiate the
prWinsockWrapper.clsWinsockMain class.
I need the winsock control to be able to accept more than
one connection request. For this, I created a
control array for the Winsock control.
Sometimes, the Winsock close event is already fired even
though there are still data need to be sent out. So, I
get the error "340 (Control array element '2' doesn't
exist)" in the SendData method.
How can I avoid this problem ? Thanks a lot.
Public Event wClose(index As Integer)
:
Private m_arrSockets() As Integer
Private m_lLocalPort As Long
Private m_iSockets As Integer
Private WithEvents f As frmWinsock
Public Sub SendData(index As Integer, ByVal sStr As
String)
f.tcpServer(index).SendData sStr '-->err = 340 ; error
= Control array element '2' doesn't exist
DoEvents
End Sub
Private Sub Class_Initialize()
m_iSockets = 0
ReDim m_arrSockets(m_iSockets)
m_arrSockets(m_iSockets) = 1
Set f = New frmWinsock
End Sub
Private Sub Class_Terminate()
Unload f
Set f = Nothing
End Sub
Private Sub f_fClose(index As Integer)
f.tcpServer(index).Close
Unload f.tcpServer(index)
m_arrSockets(index) = 0
If index = m_iSockets Then
m_iSockets = m_iSockets - 1
End If
RaiseEvent wClose(index)
end sub
Private Sub f_fConnectionRequest(index As Integer, ByVal
requestID As Long)
Dim iIx As Integer
Dim iAvailableSocket As Integer
If index = 0 Then
iAvailableSocket = GetAvailableSocket
If iAvailableSocket = -1 Then
m_iSockets = m_iSockets + 1
iIx = m_iSockets
ReDim Preserve m_arrSockets(iIx)
Else
iIx = iAvailableSocket
End If
m_arrSockets(iIx) = 1
Load f.tcpServer(iIx)
f.tcpServer(iIx).LocalPort = m_lLocalPort
f.tcpServer(iIx).Accept requestID
End If
RaiseEvent wConnectionRequest(index, requestID)
end sub
|