Re: Winsock.State question
Just so you know, Sleep freezes your program's entire thread, I don't know why you're using it. And, 6 is connecting, which means in between the time you receive the second messagebox, the socket has finished connecting.
The Winsock states are
* sckClosed = 0 - Default. Closed
* sckOpen = 1 - Open
* sckListening = 2 - Listening
* sckConnectionPending = 3 - Connection pending
* sckResolvingHost = 4 - Resolving host
* sckHostResolved = 5 - Host resolved
* sckConnecting = 6 - Connecting
* sckConnected = 7 - Connected
* sckClosing = 8 - Peer is closing the connection
* sckError = 9 - Error
Re: Winsock.State question
I have had the same problem before, what I did was make it check using a timer every 500ms.. Works for me..
Charles
Re: Winsock.State question
Thats because winsock is asynchronous and event driven... while the first msgbox is there (you havent closed the window yet), the connection process has finished in the background.
Re: Winsock.State question
It would be best to forget linear programming when using winsock... keep in mind its event driven... while your in one event another event could fire
Re: Winsock.State question
heres my exact code i used..
VB Code:
Private Sub Timer3_Timer()
Dim strState As String
Select Case Winsock3.State
Case sckClosed
strState = "Closed"
Text4.BackColor = &HFF&
Text4.Text = "Not Connected": Command8.Enabled = False: Command9.Enabled = False: Command7.Enabled = False: Command13.Enabled = False: Command11.Enabled = False
Case sckOpen
strState = "Open"
Text4.Text = "Port Open"
Case sckListening
strState = "Listening"
Text4.Text = "Listening..."
Case sckConnectionPending
strState = "Connection pending"
Case sckResolvingHost
strState = "Resolving host"
Case sckHostResolved
strState = "Host resolved"
Case sckConnecting
strState = "Connecting"
Text4.BackColor = &HFF00&: Text4.Text = "Connecting"
Case sckConnected
strState = "Connected"
Text4.BackColor = &HFF00&: Text4.Text = "Connected": Command8.Enabled = True: Command7.Enabled = True: Command9.Enabled = True: Command13.Enabled = True: Command11.Enabled = True
Case sckClosing
strState = "Peer is closing the connection"
Case sckError
strState = "Error"
Text4.BackColor = &H80FFF
Text4.Text = "Error"
Command9.Enabled = False
Command8.Enabled = False
Command7.Enabled = False
Command13.Enabled = False
Command11.Enabled = False
End Select
StatusBar1(5).Panels(3).Text = strState
End Sub
Of course, all the extra command, and text backcolors are specific to my program but will show ya what I did.. It puts the result in a status panel.
Charles
Re: Winsock.State question
Thanks for all advices, and codes.
I understand it yet.
I know, that winsock events are the best way for it, but I was very curious. . .
Re: Winsock.State question
It would be better to just wait for the Connect event to fire rather than checking the state.