WebUdpSendTo Function

Action

Sends a string or binary data to the specified host port combination using the UDP protocol. In contrary to the TCP protocol UDP is an unreliable communication where no logical connection has to be established, but before WebUdpSendTo can be used, a valid handle has to be created with the WebUdpCreate command. This handle can be used in subsequent calls to the WebUdpRecvFrom function to receive reply data. If the UDP socket (represented by the handle) has not been bound to a specific port by the WebUdpCreate function, the system automatically assigns a free port during the WebUdpSendTo function. This port can subsequently be queried by a call to the WebUdpGetBinfInfo function.

Include file

WebAPI.bdh

Syntax

WebUdpSendTo( in hUdp     : number,
              in sHost    : string,
              in nPort    : number,
              in sData    : string,
              in nDataLen : number optional ): boolean;

Return value

  • true if the data is sent successfully

  • false otherwise

Parameter Description
hUdp Valid UDP handle, that has been created by WebUdpCreate.
sHost Host name or IP address, for example, "box1.hostname.com" or "192.231.34.1".
nPort Port to send the data to.
sData Data that should be sent.
nDataLen Number of bytes to send to the server (optional). If this parameter is omitted all available data is sent.

Example

dcltrans
  transaction TWeb
    var
    nUdp  : number;
      sBuf  : string;
      sIp   : string;
    nPort : number;
  begin
    WebUdpCreate(nUdp);
    WebUdpSendTo(nUdp, "10.5.2.103", 9998, "1234567890");
    WebUdpGetBindInfo(nUdp, sIp, nPort);
    print("bound to "+sIp+" : "+string(nPort));
    WebUdpRecvFrom(nUdp, sBuf, STRING_COMPLETE, sIp, nPort);
    print("got data from "+sIp+" : "+string(nPort));
    WebUdpClose(nUdp);
    print(sBuf);
  end TWeb;