LassoScript Utility
Basics Browse Detail

[Net->WriteTo]

Tag Link [Net->WriteTo] Category Networking
Type Member Source Available Yes
Support Preferred Version 7.0
Change Unchanged Data Source Any
Output Type Integer Security None
Implementation LCAPI Sets Lasso 8.5, Lasso 8.0, Lasso 7.0

Description

[Net->WriteTo] is used with UDP connections to send data to a remote host. The first two parameters to the tag specify the DNS host name or IP address of the remote machine to be connected to and the port to be connected to.

The third required parameter for [Net->WriteTo] is the data string to be written into the connection. An optional fourth and fifth parameter specify an offset and length in the data to be written. This allows only a portion of a string to be written for protocols which require data to be formatted in blocks.

The tag returns the number of bytes that were written into the connection.

Syntax

<?LassoScript
Variable: 'Connection' = (Net);
$Connection->(SetType: Net_TypeUDP);
Variable: 'DNS_Query' = (DNS_Lookup: 'www.example.com',-rawquery);
Variable: 'Length' = $Connection->(WriteTo: 'dns.example.com', 53, $DNS_Query);
...
$Connection->Close;
?>

Parameters

Required Parameters
Host The DNS host name or IP address of the remote host.
Port The port to connect to.
Data The data to be written into the connection.
Optional Parameters
Offset Optional offset into the data to be written.
Length Optional length of the data to be written.

Examples

To connect to a remote server using UDP:

Use the [Net] type and its member tags to send data to a remote server via UDP and then to listen for a response. The following example sends data to an example time server and then listens for the current date and time to be sent back on port 8000.

[Variable: 'myConnection' = (Net)]
[$myConnection->(SetType: Net_TypeUDP)]
[Var: 'Result' = $myConnection->(WriteTo: 'time.example.com', 8000, 'TIME')]
[$myConnection->(Close)]
[Variable: 'myListener' = (Net)]
[$myListener->(SetType: Net_TypeUDP)]
[$myListener->(Bind: 8000)]
[Var: 'Output' = $myListener->(ReadFrom: 32768)]
[$myListener->(Close)]
Time server at [Output: $Output->Second]
reports the time as [Output: $Output->First].

Time server at www.example.com reports the time as 9/23/2003 12:13:35 PM