Link to home
Start Free TrialLog in
Avatar of b001
b001Flag for Afghanistan

asked on

Check if WAN machine is online before connecting

Hi Expert
I use the following code to connect to a server on WAN using ipaddress.

lcStr = "Driver={SQL SERVER};Server=&SERVERIP;Database=Auto;UID=myname;pwd=mypass;Trusted_Connection=no;"
lnHandle = Sqlstringconnect(lcStr)
If lnHandle>=1
      lnResult = SQLExec(lnHandle, "SELECT * FROM loged ", "cOutData2")
endif

it works fine,but if the server is off line it takes a long time to come back.

Is there any way I can check this ipaddress machine is online before trying to get the information?
Thanks
Avatar of Pavel Celba
Pavel Celba
Flag of Czechia image

You may use following code (source: www.News2news.com):
DO declare
 
LOCAL nDst, nHop, nRTT
nDst = inet_addr("217.198.114.255")  && celba.cz
 
STORE 0 TO nHop, nRTT
 
IF GetRTTAndHopCount(nDst, @nHop, 50, @nRTT) <> 0
    ? "Hop count to the destination:", nHop
    ? "Round-trip time, in milliseconds:", nRTT
ELSE
* on error, GetLastError may still return zero
    ? "Error"
ENDIF
* end of main
 
PROCEDURE declare
    DECLARE INTEGER GetRTTAndHopCount IN Iphlpapi;
        INTEGER DestIpAddress, LONG @HopCount,;
        INTEGER MaxHops, LONG @RTT
 
    DECLARE INTEGER inet_addr IN ws2_32 STRING cp

Open in new window

but it also takes time when you are not connected...
ASKER CERTIFIED SOLUTION
Avatar of Pavel Celba
Pavel Celba
Flag of Czechia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial