-
Reconnecting Winsock
Hi:wave:
I've created an internet cafe manager software for my own internet cafe. I created to pieces of program; one for the server and the other one is for the clients. Sometimes I'm having problem with the network connection so I'm planning to add a feature in the client wherein it will reconnect to the server every time it fails to connect. I've tried to use a timer for the client to reconnect whenever a connection with the server doesn't established but I always got an error message.
Sample Code:
In the Form Load
Dim rsClient As New ADODB.Recordset
rsClient.Open "select * from tblClient order by TerminalNo", connClientDB,3,3
Winsock1.RemoteHost = rsClient!IPAddress
Winsock1.RemotePort = rsClient!Port
Winsock1.Connect
rsClient.Close
Set rsClient = Nothing
----------------------------------------------------------------------
In the Timer
Dim rsClient As New ADODB.Recordset
rsClient.Open "select * from tblClient order by TerminalNo", connClientDB,3,3
If Winsock1.State <> sckConnected then
Winsock1.RemoteHost = rsClient!IPAddress
Winsock1.RemotePort = rsClient!Port
Winsock1.Connect
End If
rsClient.Close
Set rsClient = Nothing
-
Re: Reconnecting Winsock
What does the error in question say?
Also, here's a reworked version of the second block that will help as well:
Code:
If Winsock1.State <> sckConnected then
Winsock1.close
Winsock1.Connect
End If
I took out the recordset lines, because they aren't needed once the winsock knows the address and port to connect to (which is provided in the first block of code.) Also, you need to close a winsock before trying to connect it to something; otherwise, it just sits in limbo and will throw an error if you try to connect to another computer, or accept a connection from anothe computer.
-
Re: Reconnecting Winsock
Problem Solved!!!
Thanks for the help