KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Using NET_Ping and 10013 Error
PRODUCT: 4D | VERSION: 16 | PLATFORM: Mac & Win
Published On: October 8, 2018

It can be useful to check if it is possible to communicate with a target address before actually communicating with it. An easy way to do so is to ping it.

4D's Internet Commands Plugin provides a command to do this, NET_Ping. NET_Ping can require that 4D be ran in admin mode, if not it can instead fail the procedure and return a 10013 error code.

If administrative mode or the plugin cannot be used the following utility method uses LEP to have the machine perform the ping.

// Method: Util_LEP_Ping
//
// Details:
// Pings target address
//
// Parameters:
// $1 - String Input of target address
// Output:
// $0 - Returns 1 if ping is successful or 0 if ping fails
//----------------------------------------------------------


C_LONGINT($0)
C_TEXT($1)

If (Count parameters=1)
   C_TEXT($hostname)
  
   C_TEXT($cmd_t)
   C_TEXT($in_t)
   C_TEXT($out_t)
   C_TEXT($err_t)
   C_TEXT($errStr_t)
  
   $0:=0
   $hostname:=$1
  
   If (Folder separator=":")
      $cmd_t:="ping -c 1 "+$hostname
      $errStr_t:=""
   Else
      $cmd_t:="ping -n 1 "+$hostname
      $errStr_t:="Ping request could not find host@"
   End if
  
   SET ENVIRONMENT VARIABLE("_4D_OPTION_HIDE_CONSOLE";"True")
   LAUNCH EXTERNAL PROCESS($cmd_t;$in_t;$out_t;$err_t)
  
   If ($out_t=$errStr_t)
      $0:=0
   Else
      $0:=1
   End if
End if