Hello Network experts,
I need check possibility of connect before running some code on TCP SOcket.
I use RCP socket example from reference, which works well on IPs which are available.
I got into problem, when I try to connect to nonexisting IP.
Function TCP_Connect(xIP as string, xPort as integer) As Boolean
Dim start, stop as Integer
Dim conn as Boolean
Dim TCPSocket1 as TCPSocket
TCPSocket1 = New TCPSocket
TCPSocket1.Address = xIP
TCPSocket1.Port = xPort
start = Ticks
While Not TCPSocket1.IsConnected
If TCPSocket1.LastErrorCode <> 0 then
StatusBar.text = "Socket Error: " + str(TCPSocket1.LastErrorCode)
//poll the socket to let it do its thing
stop = Ticks
//if we broke the loop because we're connected
If TCPSocket1.IsConnected then
GuardWindow.StatusBar.text= "Socket Connected in " + Str(stop - start) + " ticks"
//here would be a great place to do a synchronous read operation...
conn = true
//The socket broke out of the loop due to an error
GuardWindow.StatusBar.text= "Socket failed to connect. It took " + Str(stop - start) + _
" ticks to figure that out"
GuardWindow.StatusBar.text= "Socket closed"