I was experiencing an issue with using wait for on a simple socket based connection. For example:
I noticed that if I "wait for" sock_Connected and there's an exception thrown, the wait for never resumes. Now if instead use an independent event handler like so...
I can check the Successful result and if false check for the last exception. I was thinking I should be able to do all that after the wait for. So I am assuming if an exception occurs while waiting for an event, that wait for will sit there forever. Is this correct behavior? I thought an example of wait for in B4A with SQL that seems to demonstrate that it would gracefully return and possibly check the LastException.
To add to the discussion, I tried putting try/catch blocks around the wait for line and that didn't help - only way it works is to use a discrete sock_connected event handler routine.
For now I can re-arrange my code to work like I need it to - just looking for some clarity.
thanks!
B4X:
Dim sock As Socket
Dim Successful As Boolean
'<----this IP doesn't exist or isn't listening on specified port so connect exception will be thrown
Dim txtip As String = "10.0.0.23"
sock.Initialize("sock")
Log("Connect attempt")
sock.Connect(txtip, 51042, 10000)
'connect to nodemcu
Wait For (Successful) sock_Connected (Successful As Boolean)
Log("Returned from connection attempt")
I noticed that if I "wait for" sock_Connected and there's an exception thrown, the wait for never resumes. Now if instead use an independent event handler like so...
B4X:
Sub sock_Connected (Successful As Boolean)
Log("Connected Status:" & Successful)
If Successful = False Then
Log(LastException)
else
Log("Successfully connected...")
End If
End Sub
I can check the Successful result and if false check for the last exception. I was thinking I should be able to do all that after the wait for. So I am assuming if an exception occurs while waiting for an event, that wait for will sit there forever. Is this correct behavior? I thought an example of wait for in B4A with SQL that seems to demonstrate that it would gracefully return and possibly check the LastException.
To add to the discussion, I tried putting try/catch blocks around the wait for line and that didn't help - only way it works is to use a discrete sock_connected event handler routine.
For now I can re-arrange my code to work like I need it to - just looking for some clarity.
thanks!