|
|
ITK Programmer's Guide |
||||||||||||
|
Table of contents | Intro | General
| TCP Low Level | TCP High Level | UDP | DNS
| PPP
|
|||||||||||||
|
ITK_TCPOpen |
||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||
|
Syntax: |
streamRef := ITK_TCPOpen (hostName;remotePort;rcvBuffer;tcpOpt;oldStream;localPort;localIP)
|
|||||||||||||||||||||||||||||||||||||||||||||
|
Warning: |
All streams opened using ITK_TCPOpen MUST be released using ITK_TCPRelease .
|
|||||||||||||||||||||||||||||||||||||||||||||
|
Description: |
Opens a TCP stream asynchronously (returns control immediately
without waiting for the connection to be established with the remote
host). Use tcpOpt to open an SSL "client" stream instead of a plain TCP stream. If remotePort is equal to 443 (HTTPS standard port number), ITK will switch automatically to SSL.
|
|||||||||||||||||||||||||||||||||||||||||||||
|
Params: |
Note#1: if you add a "." at the beginning of the TCP address of the remote host (ex: "www.e-node.net"), ITK will choose randomly one of the resolved addresses returned by the DNS to do DNS load balancing (see ITK_Name2Addr for more information).
|
|||||||||||||||||||||||||||||||||||||||||||||
|
Example: |
` open a stream with an HTTP server |
|||||||||||||||||||||||||||||||||||||||||||||
|
ITK_TCPListen |
||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||
|
Syntax: |
streamRef := ITK_TCPListen (hostFilter; portFilter; localPort; rcvBuffer; tcpOpt; oldStream; localIP)
|
|||||||||||||||||||||||||||||||||||||||||||||
|
Warning: |
All streams opened using ITK_TCPListen MUST be released using ITK_TCPRelease .
|
|||||||||||||||||||||||||||||||||||||||||||||
|
Description: |
Opens a "passive" or "listening" TCP stream to receive calls. Use tcpOpt to create an SSL "server" stream instead of a TCP stream. If localPort is equal to 443 (HTTPS standard port number), ITK will switch automatically to SSL. |
|||||||||||||||||||||||||||||||||||||||||||||
|
Note: |
Under MacOS X, your application needs to run with root privileges in order to listen on ports ranging from 1 to 1023.
|
|||||||||||||||||||||||||||||||||||||||||||||
|
Params: |
|
|||||||||||||||||||||||||||||||||||||||||||||
|
Example: |
` create a TCP listening stream on HTTP port |
|||||||||||||||||||||||||||||||||||||||||||||
|
ITK_TCPClose |
||||||||||||||||
|
|
|
|||||||||||||||
|
Syntax: |
error := ITK_TCPClose (streamRef)
|
|||||||||||||||
|
Description: |
Sends the data remaining in the output buffer (see ITK_TCPSend ) and tells the remote host that
no more data will be sent.
|
|||||||||||||||
|
Warning: |
Closing a stream doesn't releases the stream, but only tells the remote host that you're done sending data.
|
|||||||||||||||
|
Params: |
|
|||||||||||||||
|
Example: |
$stream := ITK_TCPOpen("http://www.e-node.net/itk";80)
|
|||||||||||||||
|
ITK_TCPRelease |
|||||||||||||||||||||
|
|
|
||||||||||||||||||||
|
Syntax: |
error := ITK_TCPRelease (streamRef; optionFlag)
|
||||||||||||||||||||
|
Description: |
Releases a TCP stream and all its associated buffers.
|
||||||||||||||||||||
|
Note: |
When calling ITK_TCPRelease , all data remaining to be sent will not be sent. To avoid this, you must call ITK_TCPClose and then monitor ITK_TCPStatus to check that the remote host has received all remaining data and that you closed your half-stream. Each successfull calls to ITK_TCPOpen and ITK_TCPListen must be balanced by a call to ITK_TCPRelease. |
||||||||||||||||||||
|
Params: |
|
||||||||||||||||||||
|
Example: |
$stream := ITK_TCPOpen("http://www.e-node.net";80)
|
||||||||||||||||||||
|
ITK_TCPStatus |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Syntax: |
status := ITK_TCPStatus (streamRef;selector)
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Description: |
Returns the current status of a TCP stream or miscellaneous
information about the stream.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Params: |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Example: |
` wait for the connection to be established |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
|
ITK_TCPStatus2A |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Syntax: |
index := ITK_TCPStatus2A (arrStreams;arrStatus;minStatus)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Description: |
Returns the current status of an array of streams and the index of the first stream which status is greater than or equal to minStatus, or negative (error on the stream). This routine can be used to monitor the status of a list of streams and wait for a connection or a close to be acknowledged.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Params: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Example: |
ARRAY LONGINT($streams;10) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
ITK_TCPSend |
|||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||
|
Syntax: |
result := ITK_TCPSend (streamRef;data;flushFlag;filterFlag)
|
||||||||||||||||||||||||||||||
|
Description: |
Sends data through an established TCP stream.
|
||||||||||||||||||||||||||||||
|
Params: |
|
||||||||||||||||||||||||||||||
|
Example: |
$stream := ITK_TCPOpen("http://www.e-node.net/itk";80)
|
||||||||||||||||||||||||||||||
|
ITK_TCPRcv |
||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||
|
Syntax: |
result := ITK_TCPRcv (streamRef;dataStorage;maxLen;filterFlag;appendFlag;endString;timeout)
|
|||||||||||||||||||||||||||||||||||||||||||||
|
Description: |
Receives data through an established TCP stream. ITK_TCPRcv will return control immediately when the timeout is set to 0. When the timeout is not 0, ITK_TCPRcv will return when one of these conditions is valid:
|
|||||||||||||||||||||||||||||||||||||||||||||
|
Params: |
|
|||||||||||||||||||||||||||||||||||||||||||||
|
Example: |
$stream := ITK_TCPOpen("mail.e-node.net";25)
In the following example, the first call to ITK_TCPRcv will receive data until a pair of CR/LF during a maximum of 2 minutes. Then the second call to ITK_TCPRcv will append received data into http_req until a <>CRLF is received in new data received or $len data are accumulated in http_req during a maximum of 2 minutes. ` Receive HTTP header |
|||||||||||||||||||||||||||||||||||||||||||||
|
ITK_TCPChRcv |
||||||||||||||||
|
|
|
|||||||||||||||
|
Syntax: |
result := ITK_TCPChRcv (streamRef)
|
|||||||||||||||
|
Description: |
Returns the number of bytes available in the receive buffer of a TCP stream.
|
|||||||||||||||
|
Note: |
The number of bytes received after calling ITK_TCPChRcv may be greater than the value returned by ITK_TCPChRcv as some data may have been received between the two calls.
|
|||||||||||||||
|
Params: |
|
|||||||||||||||
|
Example: |
if (ITK_TCPChRcv($stream)#0) ` do we have some data available ? |
|||||||||||||||
|
ITK_TCPUnRcv |
||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||
|
Syntax: |
result := ITK_TCPUnRcv (streamRef;data; options)
|
|||||||||||||||||||||||||
|
Description: |
ITK_TCPUnRcv can be used to put some data you
previously received back into ITK's receive buffer.
|
|||||||||||||||||||||||||
|
Notes: |
The options flags parameter has been added in v2.0.4.
|
|||||||||||||||||||||||||
|
Params: |
|
|||||||||||||||||||||||||
|
Example: |
$result := ITK_TCPRcv($stream; $data) ` receive some data |
|||||||||||||||||||||||||
|
ITK_TCPStrmInfo |
|||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||
|
Syntax: |
error := ITK_TCPStrmInfo (streamRef; remoteIP; remotePort; localPort; srtt; localIP)
|
||||||||||||||||||||||||||||||||||||||||
|
Description: |
Returns information about an established TCP stream.
|
||||||||||||||||||||||||||||||||||||||||
|
Params: |
|
||||||||||||||||||||||||||||||||||||||||
|
Example: |
$err := ITK_TCPStrmInfo($stream;remAddr;remPort;locPort;srtt;locAddr) |
||||||||||||||||||||||||||||||||||||||||
|
Note: |
localPort and remotePort may return negative values, because 4D is using signed integers. To get the original positive port number, you can use the following code: C_LONGINT(locPort; remPort) ` MUST
be typed as LONGINTS !!! If (remPort < 0) |
||||||||||||||||||||||||||||||||||||||||
|
ITK_TCPWaitConn |
||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||
|
Syntax: |
result := ITK_TCPWaitConn (streamRef;minStatus;timeout)
|
|||||||||||||||||||||||||
|
Description: |
Wait for a TCP stream to be in a certain status or to return
an error (negative value). This routine is synchronous, control will be returned:
|
|||||||||||||||||||||||||
|
Params: |
|
|||||||||||||||||||||||||
|
Example: |
$stream := ITK_TCPOpen("mail.e-node.net";25)
|
|||||||||||||||||||||||||
|
ITK_SetTimeout |
|||||||||||||||||||||
|
|
|
||||||||||||||||||||
|
Syntax: |
curTimeout := ITK_SetTimeout (streamRef;newTimeout)
|
||||||||||||||||||||
|
Description: |
ITK_SetTimeout can be used to set the default timeout used by all "send" ITK routines (ITK_TCPSend, ITK_TCPSendFile, ITK_TCPSendPict, ITK_TCPSendBlob). By default, ITK doesn't use any timeout when sending data. It can be usefull to set a timeout to avoid possible "send locks" when the remote host becomes unreachable (crash or disconnection for example). When the send timeout is reached in one of the ITK_TCPSend routines, the routine will return control , but the status of the stream will remain the same. The best place to set the timeout for a given stream is just after a successfull call to ITK_TCPOpen or ITK_TCPListen . |
||||||||||||||||||||
|
Params: |
|
||||||||||||||||||||
|
Example: |
$stream := ITK_TCPOpen("mail.e-node.net";25)
|
||||||||||||||||||||