Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Testing for IP Connection
Message
De
12/05/2003 15:23:37
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Applications Internet
Divers
Thread ID:
00773323
Message ID:
00787469
Vues:
17
Steven, I don't know if you have found a solution yet, but this is some code that I have found that seems to work for me. You may try it to see.
*!* ping www.microsoft.com - returns "Connected" if connection exists and is connected.
?pingstate("www.microsost.com") 

FUNCTION PingState
	LPARAMETERS m.lcHttpAddress
	* modified code originally by josh@jassing.com
	* with LOTS of help from (actually; all the hard work by) Markus Voellmy

	* NOTE: it does not do any dns lookups; so if you're checking for a mail server, you need
	* to resolve the mx record yourself.

	
	#DEFINE sckClosed 0
	#DEFINE sckOpen 1
	#DEFINE sckListening 2
	#DEFINE sckConnectionPending 3
	#DEFINE sckResolvingHost 4
	#DEFINE sckHostResolved 5
	#DEFINE sckConnecting 6
	#DEFINE sckConnected 7
	#DEFINE sckClosing 8
	#DEFINE sckError 9

	LOCAL lcState

	m.lcHttpAddress = iif(type("m.lcHttpAddress") <> "C" or empty(m.lcHttpAddress),"www.microsoft.com",m.lcHttpAddress)
	m.lcHttpAddress = iif(left(upper(m.lcHttpAddress),7) = "HTTP://",substr(m.lcHttpAddress,8),m.lcHttpAddress)

	tnState =  pingx( m.lcHttpAddress ,80 ) 

	DO CASE
		CASE tnState = sckClosed
			lcState = "Closed"
		CASE tnState = sckOpen
			lcState = "Open"
		CASE tnState = sckListening
			lcState = "Listening"
		CASE tnState = sckConnectionPending
			lcState = "Waiting"
		CASE tnState = sckResolvingHost
			lcState = "Resolving"
		CASE tnState = sckConnecting
			lcState = "Connecting"
		CASE tnState = sckConnected
			lcState = "Connected"
		CASE tnState = sckClosing
			lcState = "Closing"
		CASE tnState = sckError
			lcState = "Error"
		OTHERWISE
			lcState = "Unknown"
	ENDCASE
	RETURN lcState

FUNC pingx
	LPARAM tcServer, tnPort
	LOCAL lnState, loPing, lnLast
	loPing=CREA("mswinsock.winsock")
	WITH loPing
		.remoteport=tnPort
		.remotehost = tcServer
		.CONNECT()
		lnLast = -1
		DO WHILE .state < sckConnected
			IF lnLast # .state
				lnLast = .state
			ENDIF
		ENDDO
		lnState = .state
		.CLOSE()
	ENDWITH
	RETURN lnState
ENDFUNC
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform