close

Lparameters tcWhere, tnWhichPort
Local lReturnValue
* by josh@jassing.com
* with LOTS of help from (actually; all the hard work by) Markus Voellmy
* wrapped up as a big function by Lou Harris
*
* ? pingstate( pingx( "www.jassing.com",80 ) )
* would check jassing.com to be sure it's running a web server
* 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.
If Vartype(tnWhichPort) # "N"
 tnWhichPort = 80
Endif
*? pingstate( pingx( "www.jassing.com",80 ) )
lReturnValue = pingstate( pingx( m.tcWhere, m.tnWhichPort ) )
Return m.lReturnValue
#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
Func PingState
 Lparam tnState
 Local lcState
 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

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 hsiung03 的頭像
    hsiung03

    hsiung.博格 ERP軟體

    hsiung03 發表在 痞客邦 留言(0) 人氣()