Receives data 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 WebUdpRecvFrom can be used, a valid handle has to be created with the WebUdpCreate command. If the UDP socket (represented by the handle) has not been bound to a specific port by the WebUdpCreate function, calls to WebUdpRecvFrom will fail until the first WebUdpSendTo function is called, which assigns a system generated port.
WebAPI.bdh
WebUdpRecvFrom( in hUdp : number, out sData : string optional, in nMaxData : number optional, out sFromIp : string optional, out nFromPort : number optional): boolean;
true if the data has been received successfully
false otherwise
Parameter | Description |
---|---|
hUdp | Valid UDP handle, that has been created by WebUdpCreate. |
sData | String where the received data should be stored (optional). If this parameter is omitted the received data is discarded. |
nMaxData | The maximum number of bytes that should be read (optional). Omit this parameter or specify STRING_COMPLETE to receive as much data as is available. |
sFromIp | String that will receive the IP address of the host, which sent the data (optional). |
nFromPort | Variable, that will receive the source port (optional). |
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;