Page 1 of 1
Timeout for OpenNetworkConnection
Posted: Sun Oct 18, 2009 6:59 pm
by Marlin
Connection = OpenNetworkConnection(ServerName$, Port [, Mode[, Timeout]])
Wenn trying to connect by tcp to a http server, that appeared to be down,
I found that OpenNetworkConnection() took about 5 minutes to return.
= Program execution halts for about 5 minutes
(I used a Linux machine to try that connect.)
When the server is availlable, it takes only a few,
but allways less than 20 seconds to open
the network connection.
(Same conditions on the client side)
Re: Timeout for OpenNetworkConnection
Posted: Mon Oct 19, 2009 1:50 pm
by Num3
I use this code, for a quicker check:
Code: Select all
Structure myEcho
Reply.ICMP_ECHO_REPLY
Buffer.l[20]
EndStructure
ping.myEcho
server.s = "192.168.1.1"
tOut.l = 5 ; <- TIME OUT
hP = IcmpCreateFile_()
If hP
con.i = IcmpSendEcho_(hP, inet_addr_(@server), @"HI", Len("HI"), 0, @ping, SizeOf(myecho), tOut)
IcmpCloseHandle_(hP)
EndIf
If con = 0 ; Connection to 192.168.1.1 failed !
; Do something here
EndIf
Re: Timeout for OpenNetworkConnection
Posted: Mon Oct 19, 2009 2:26 pm
by Marlin
Num3 wrote:I use this code, for a quicker check:
...
Your code seems to be specific for some type of platform (Windows?)
I'd rather prefer simple solutions in native PB code.
I came up with
this solution with the use of threading.
(That should work on all supported platforms; I only tried it on my Linux machine yet.)
However my above suggestion looks much nicer and simpler,
and is probably much more appealing to anyone considering
the use of such a feature.
