TCP-Client Operations

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Internet and Network > TCP-Client Commands >

 TCP-Client Operations

TCP.Close

Previous Top Next


SPR Script Language

 

TCP.Close

Closes an open TCP client connection.

 

Intention

 

The TCP.Close command terminates an active TCP client connection identified by its socket handle ($$HND). It is crucial to close connections when they are no longer needed to release system resources. After a connection is closed, the handle becomes invalid and cannot be used for further network operations.

 

Illustration

 

          [Client Script]           [Network Server]
                |                           |
                |   TCP/IP Connection       |
TCP.Close <---------- (Socket HND) ---------->
(Socket HND)

 

Syntax

 

TCP.Close|$$HND

 

Parameter Explanation

 

P1 - $$HND - (Variable, Numeric, Required)

The socket handle of the open TCP connection to be closed, obtained from TCP.Open.

 

Return Value (on Stack)

 

The command pushes 1 onto the stack to indicate that the close operation was attempted.

 

Examples

 

'***********************************

' TCP.Close - Sample 1: Close a TCP Connection

'***********************************

TCP.Open|127.0.0.1|5556

POP.$$HND

JIZ.$$HND|Error_Handler

' ... send/receive data ...

TCP.Close|$$HND

POP.$$CLOSE_STATUS ' Get the status (always 1)

PRT.Connection closed.

 

Remarks

 

- It is good practice to close all open TCP connections when they are no longer needed to free system resources.

- Attempting to use a closed handle will result in an error.

- The return value (1) indicates that the close operation was initiated, not necessarily that the remote end has acknowledged the close.

 

See also:

 

TCP.Open

TCP.Send

TCP.Recv

TCP.LineInput