2011年5月1日 星期日

[VFP] winscok

瀏覽數
LPARAMETERS lcServer, lnPort, lcDebug LOCAL lnState, loPing, lnLast * * Ping utility Ver 1.4 * *** Input : * * lcServer - Host name to ping * lnPort - Port number to ping * lcDebug - .T.: Display status message * *** Output : * 來源: * .T. - Ping successfully * .F. - Ping Fail * * Description : Ping a host for specify port availability * Require Microsoft Winsock ActiveX version 6.0 (SP4) * mswinsck.ocx - 109,248 來源: bytes * locate at C:\WINDOWS\SYSTEM32 * * Example: ? PING('jassing.com',80) would check jassing.com to be sure it's running a web server * * 24/05/2005 - Error handling when winsock is not proper installed * 05/08/2004 - Ping delay 來源: increase to 1/10 sec instead of 1/20 sec * 13/04/2002 - Last status message show 2 seconds before leave when debug is 'ON' * 12/04/2002 - Minor code updated * 11/04/2002 - Code modify from original * * By: josh@jassing.com modified by Tommy Tsang * #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 loPing = CREATEOBJECT('mswinsock.winsock') IF VARTYPE(loPing) = 'O' WITH loPing .remoteport = lnPort .remotehost = lcServer .CONNECT() lnLast = -1 DO WHILE .state < sckConnected IF lnLast <> .state PINGSTATE(.state, lcDebug) lnLast = .state ELSE * * Wait a little while to release the loading of system * INKEY(.1) && Delay 1/10 second ENDIF ENDDO   PINGSTATE(.state, lcDebug) lnState = .state .CLOSE() PINGSTATE(.state, lcDebug, 2) ENDWITH ENDIF RETURN lnState <> sckError PROCEDURE PINGSTATE LPARAMETERS lnState, lcDebug, lnTimeOut LOCAL lcState IF lcDebug DO CASE CASE lnState = sckClosed lcState = 'Closed' CASE lnState = sckOpen lcState = 'Open' CASE lnState = sckListening lcState = 'Listening' CASE lnState = sckConnectionPending lcState = 'Waiting' CASE lnState = sckResolvingHost lcState = 'Resolving' CASE lnState = sckConnecting lcState = 'Connecting' CASE lnState = sckConnected lcState = 'Connected' CASE lnState = sckClosing lcState = 'Closing' CASE lnState = sckError lcState = 'Error' OTHERWISE lcState = 'Unknown' ENDCASE IF VARTYPE(lnTimeOut) = 'N' WWAIT('Ping State: ' + lcState, .F., lnTimeOut) ELSE WWAIT('Ping State: ' + lcState) ENDIF ENDIF RETURN lcState

沒有留言: