Command UDP Commands, Overview

4D Internet Commands

UDP Commands, Overview

version 11


UDP (User Datagram Protocol) is an easy-to-implement protocol for sending data. It is faster and simpler than TCP (only 8 bytes of header as opposed to at least 20 bytes in TCP), but it does not offer the same level of reliability. It is useful for applications where data must arrive at their destination quickly. However, it does not allow verification of delivery, nor does it allow error-checking or recovery of data that was not delivered correctly.

Example

The following example illustrates how the list of 4D Servers running on a local network can be retrieved using UDP commands:

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

   $Addr:="255.255.255.255"
   $Port:=19813
   $Offset:=32
   SET BLOB SIZE($Blob;96;0)
   TEXT TO BLOB("4D Server";$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(asHost;$PeerAddr)
            APPEND TO ARRAY(asMachineName;$Host)
            APPEND TO ARRAY(asService;$Service)
            APPEND TO ARRAY(asDBName;$DBName)
         End if
      End if
   Until(Milliseconds>$Timeout) | ($Err#0))
   $Err:=UDP_Delete($udpID)

See Also

Low Level Routines, Overview.