Creates an UDP handle, which can be used in subsequent calls to WebUdpXXX functions. If this handle is no longer used, call WebUdpClose to free all associated system resources. The optional IP and port parameters can be used to explicitly bind the UDP socket to a single IP and/or port. This has to be done if a WebUdpRecvFrom function is called before a WebUdpSendTo. If the socket is not bound, the latter function automatically binds it to a system generated port. This port can be queried by the WebUdpGetBindInfo function.
WebAPI.bdh
WebUdpCreate( out hUdp : number, in sIp : string optional, in nPort : number optional ): boolean;
true if the handle has been created successfully
false otherwise
Parameter | Description |
---|---|
hUdp | UDP handle, that has to be created. |
sIp |
IP address to bind the UDP socket to (optional). Must be a valid IP address for the local machine. If this parameter is omitted, or a null value is specified no specific IP address is bound. Therefore data can be sent to (and read from) any valid IP of the local host. |
nPort |
Port to bind the UDP socket to (optional). Specify this parameter to assign a special port to the UDP socket. If this parameter is omitted no special port is assigned and the next WebUdpSendTo function will bind the socket to a system generated port. If this parameter is omitted calls to WebUdpRecvFrom will fail unless the first WebUdpSendTo function is called. |
dcltrans transaction TWeb var nUdp : number; sBuf : string; sIp : string; nPort : number; begin WebUdpCreate(nUdp, null, 9999); WebUdpRecvFrom(nUdp, sBuf, 300, sIp, nPort); print("got data from "+sIp+" : "+string(nPort)); WebUdpClose(nUdp); print(sBuf); end TWeb;