I have written three applications to transfer data from remote Clients to the Central Server and then back from Central Server to the remote Clients. The Server simply listens for incoming connections from any of the remote Clients. When a request for connection comes in, the Server starts a new Host in a separate thread. The Host then starts a winsock control in listening mode, tells the Server what Port it is listening on, which in turn tells the Client which port it should connect to. The Client then closes its connection with the Server, then starts a new connection with the Host. Once connected, the data synchronization can begin as normal. Once the Synchronization is complete, the Client closes its connection with the Host. At that time, the Host is unloaded.
The host that the server creates is an ActiveX EXE called cWinsock and the Server application previously sets a reference to that EXE to use its methods. Following is the code that i used in the server application:
Dim WinsockHost As cWinsockHost, LoadF As cWinsockHost
Set LoadF = New cWinsockHost
LoadF.Load
Note: The load method simply loads the main form of the host. The form must be loaded otherwise if the remote Client tries to connect repeatedly after a certain set interval of time, the connection is successful only few times. Afterwards, the Server application sends a zero port number back to the client and the client's connection to the host is unsuccessful, the host erroring with the following message:
"Socket not bound, invalid address or the listen is not invoked prior to accept"
Set WinsockHost = New cWinsockHost
lngPort = WinsockHost.Listen 'the listen method shows the main form, starts a winsock control in listening mode and tells the Server what Port it is listening on
For i = 0 To MAX_SESSIONS
If Winsock2(i).State = sckClosed Then
Winsock2(i).Accept requestID
Me.Winsock2(i).SendData "PORT" & lngPort
Set LoadF = Nothing
Set WinsockHost = Nothing
DoEvents
Exit For
End If
Next i
Everything seems to work OK with one exception. The server is left overnight in listening mode. The Client is set to automatic synchronization mode and initiates connection every 15 minutes or 30 minutes to the server. When a request for connection comes in, the Server starts a new Host in a separate thread. In doing so, the server first calls the load method to load the Host main form and then calls the Listen method to request the Host to start a winsock control in listening mode, and to inform the Server what Port the host is listening on (as explained above). The problem that i am encountering is that after 10 or 15 times of connections initiated by the client, the memory consumption on the server machine gradually increases to a point that the server refuses to accept any connection requests from the client and gives an OUT OF MEMORY message. I could not figure out yet why is it so as i am setting the host created to nothing after each connection. Can someone pinpoint the problem or any suggesssions regarding that issue. I will appreciate that.
Thanks,