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).
|
|||||||||||||||||||||||||||||||||||||||||||||
Params: |
Note#1: if you add a "." at the beginning of the TCP address of the remote host (ex: ".www.internet-toolkit.com"), 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: |
$stream := ITK_TCPOpen("www.internet-toolkit.com";80) If ($stream#0) ... $err := ITK_TCPRelease($stream) End If |
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.
|
|||||||||||||||||||||||||||||||||||||||||||||
Params: |
|
|||||||||||||||||||||||||||||||||||||||||||||
Example: |
$stream := ITK_TCPListen(0;0;80) ` listen on HTTP port number If ($stream#0) ... $err := ITK_TCPRelease($stream) End If |
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("www.internet-toolkit.com";80) If ($stream#0) ... $err := ITK_TCPClose($stream) ... $err := ITK_TCPRelease($stream) End If |
ITK_TCPRelease |
||||||||||||||||
Syntax: |
error := ITK_TCPRelease(streamRef)
|
|||||||||||||||
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("www.internet-toolkit.com";80) If ($stream#0) ... $err := ITK_TCPRelease($stream) End If |
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 Repeat $s := ITK_TCPStatus($stream) IDLE Until (($s>=8) | ($s<0)) ` end if connected or error |
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) ARRAY LONGINT($status;10) For ($i;1;10) $streams{$i} := ITK_TCPListen(0;0;80) End For ` wait for the connection to be established on a list of streams Repeat $i := ITK_TCPStatus2A($streams; $status; 8) If ($i>0) $s := ITK_TCPStatus($streams{$i}) Case of :($s >= 8) ` stream connected ... ` handle the HTTP hit :($s<0) ` error on stream $err := ITK_TCPRelease($streams{$i}) $streams{$i} := ITK_TCPListen(0;0;80) ... End Case End If Until (quit) |
ITK_TCPSend |
|||||||||||||||||||||||||||||||
Syntax: |
result := ITK_TCPSend(streamRef;data;flushFlag;filterFlag)
|
||||||||||||||||||||||||||||||
Description: |
Sends data through an established TCP stream.
|
||||||||||||||||||||||||||||||
Params: |
|
||||||||||||||||||||||||||||||
Example: |
$stream := ITK_TCPOpen("www.internet-toolkit.com";80) If ($stream#0) ... ` wait for connection to be established ` use ITK's send buffer $err := ITK_TCPSend($stream;"GET / HTTP/1.0"+$crlf;1) ` Flush ITK's send buffer $err := ITK_TCPSend($stream;"User-Agent: myWebBrowser/1.0"+$crlf+$crlf) ... |
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:
|
|||||||||||||||||||||||||||||||||||||||||||||
Params: |
|
|||||||||||||||||||||||||||||||||||||||||||||
Example: |
$stream := ITK_TCPOpen("mail.internet-toolkit.com";25) if ($stream#0) ... ` wait for connection to be established $rcvdLen := ITK_TCPRcv($stream; $data) ... |
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 ? $result := ITK_TCPRcv($stream;$buff) ... |
ITK_TCPUnRcv |
|||||||||||||||||||||
Syntax: |
result := ITK_TCPUnRcv(streamRef;data)
|
||||||||||||||||||||
Description: |
ITK_TCPUnRcv can be used to put some data you
previously received back into ITK's receive buffer.
|
||||||||||||||||||||
Params: |
|
||||||||||||||||||||
Example: |
$result := ITK_TCPRcv($stream; $data) ` receive some data if ($data # "+OK@") $err := ITK_TCPUnRcv($stream;$data) ` put it back in ITK's buffer to receive it again |
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) ALERT("Remote host address: "+ITK_Addr2Name(remAddr;2)) |
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.internet-toolkit.com";25) ` wait for connection to be established $status := ITK_TCPWaitConn($stream;8) If ($status=8) ... End If $err := ITK_TCPRelease($stream) |