I am working on an old VB6 application. The application uses the RAS API to establish a modem connection, and then uses the winsock control to connect to the IP address and port.
Now I am adding a failover function for this application, where if it cannot connect to the server, it tries to connect to the next one in the list.
Let's say I have two servers: server application A and server application B. (During my tests, I exchanged them to make sure both servers are accessible and there is no routing / firewall problem.)
If I stop server application A, then something rather strange will happen when the application tries to connect to server application A, and then to server application B:
mySocket.close
mySocket.Connect serverA, portA
- mySocket.state = 6 sckConnecting
- The connect socket event is called
- mySocket.state = 7 sckConnected
- mySocket.state = 8 sckClosing
(which seems a little odd: I'm not sure why it seems to connect for a few moments.)
The socket remains in sckClosing state. After a few hundred milliseconds, I will move on to trying to connect to server B:
mySocket.close
- mySocket.state = 0 sckClosed
.
mySocket.Connect serverB, portB
- mySocket.state = 6 sckConnecting Socket Error Event
- called with error 10060 (WSAETIMIMOUTOUT)
- mySocket.state = 9 sckError
At this point, if I run server application A, do RAShangup and RASdial and try to connect to server A, everything works fine.
socket.connect ip, port
socket.close
socket.connect newIP, newPort
, RAShangup RASdial. WSAETIMEDOUT.
-, ?
. , , :
Private Sub closeSocket(ByRef w As Winsock)
w.Close
Do While (w.State <> sckClosed)
DoEvents
Loop
End Sub