4D v13.2

UDP Commands, Overview

Home

 
4D v13.2
UDP Commands, Overview

UDP Commands, Overview  


 

 

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 TEXT(asHost;0)
 ARRAY TEXT(asMachineName;0)
 ARRAY TEXT(asService;0)
 ARRAY TEXT(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 II";$Blob;Mac Text without length;$Offset)
 
 $Err:=UDP_New(0;$udpID)
 $Err:=UDP_SendBLOBTo($udpID;$Addr;$Port;$Blob)
 $Secs:=5
 $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=-1)
          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)

 
PROPERTIES 

Product: 4D
Theme: IC UDP

 
SEE ALSO 

Low Level Routines, Overview