KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: A utility method to list 4D Server running on a Network
PRODUCT: 4D | VERSION: 12 | PLATFORM: Mac & Win
Published On: August 1, 2011

If you are managing a number of 4D servers on a network, the utility method below will facilitate checking to see if one or all of the servers are visible for log on for 4D remote connections. This code originated in the UDP Commands, Overview and has been updated to account for changes that have happened over time and to be a method that can be used programmatically.

The method should be called as shown below. $1 should be "2004" or a version later; $2 is the IP address or the host machine; $3 is the port number (19813 is the default, change if the application port has been change).

ARRAY STRING(255;asHost;0)
ARRAY STRING(32;asMachineName;0)
ARRAY STRING(32;asService;0)
ARRAY STRING(32;asDBName;0)

4DServersBroadcasting( "2004" | "11" | "12" ; "nnn.nnn.nnn.nnn" ; 19813\
    ->asHost\
    ->asMachineName\
    ->asService\
    ->asDBName)


C_TEXT($Vers_T;$1)
C_TEXT($Addr;$2)
C_LONGINT($Port;$3)
C_POINTER({$4})

C_LONGINT($udpID;$Offset;$Build_L;$Vers_L;$Secs;$Err;$Timeout;$Port;$Offset;$Pos)
C_TEXT($ServerStr_T;$PeerAddr;$Host;$Service;$DBName)
C_BLOB($Blob)
C_POINTER($Host_aP;$MachineName_aP;$Service_aP;$DBName_aP)

$Vers_T:=$1
$Addr:=$2
$Port:=$3
$Host_aP:=$4
$MachineName_aP:=$5
$Service_aP:=$6
$DBName_aP:=$7

If ($Vers_T="2004")
   // 4D Server 2004 and earlier
   //

   $ServerStr_T:="4D Server 6.5"
Else
   // 4D Server v11 and later
   //

   $ServerStr_T:="4D Server II"
End if

$Offset:=32
SET BLOB SIZE($Blob;96;0)
TEXT TO BLOB($ServerStr_T;$Blob;Mac text without length;$Offset)

$Err:=UDP_New (0;$udpID)
$Err:=UDP_SendBLOBTo ($udpID;$Addr;$Port;$Blob)
$Secs:=2
$Timeout:=Milliseconds+($Secs*1000)
Repeat
   DELAY PROCESS(Current process;6) //... in ticks
   SET BLOB SIZE($Blob;0;0)
   $PeerAddr:=$Addr
   $Err:=UDP_ReceiveBLOBFrom ($udpID;$PeerAddr;$Port;$Blob)

   If (BLOB size($Blob)>0)
      $Offset:=0
      $Host:=BLOB to text($Blob;Mac C string;$Offset;32)
      $Offset:=32
      $Service:=BLOB to text($Blob;Mac C string;$Offset;32)
      $Offset:=64
      $DBName:=BLOB to text($Blob;Mac C string;$Offset;32)
      $Pos:=Find in array(asMachineName;$Host)
      If ($Pos<0)
         APPEND TO ARRAY($Host_aP->;$PeerAddr)
         APPEND TO ARRAY($MachineName_aP->$Host)
         APPEND TO ARRAY($Service_aP->;$Service)
         APPEND TO ARRAY($DBName_aP->;$DBName)
      End if
    End if
Until ((Milliseconds>$Timeout) | ($Err#0))
$Err:=UDP_Delete($udpID)