HTP. - Command Library

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Internet and Network >

HTP. - Command Library

!TCP-Client Commands

Previous Top Next


SPR Script Language

 

!TCP-Client Commands

Low-level commands for establishing and managing a TCP client connection.

 

Intention

 

While the HTP-MCP commands are used to create and manage the MCP server, the commands in this section are the tools needed to communicate with it from a client script. They provide the fundamental building blocks for a standard TCP client workflow: opening a connection, sending data, receiving a response, and closing the connection.

 

Although designed to work with the MCP server (by sending it JSON command strings), these are general-purpose TCP commands and can be used to communicate with any standard TCP server on a network.

 

Example Workflow

'

'SPR Script-file: Send_Command_To_MCP.spr

'Purpose: Demonstrates the full lifecycle of a TCP client connection.

'

#LIB:?path\..\Library

SAV.Save|$$CMD|$$RES|$$HND|$$TOS

 

' 1. Define the JSON command to send

VAR.$$CMD={"action":"ping"}

 

' 2. Open the connection to the server

TCP.Open|127.0.0.1|5556|5000

POP.$$HND

JIZ.$$HND|Lab_failed

 

' 3. Send the command string

TCP.Send|$$HND|$$CMD

 

' 4. Receive the server's response

TCP.Recv|$$HND|4096|$$RES

POP.$$TOS ' Discard the byte count from the stack

 

' 5. Close the connection

TCP.Close|$$HND

 

PRT.Server Response: $$RES

GTO.Lab_success

 

:Lab_failed

MBX.Failed to communicate with the MCP Server!|Stop

:Lab_success

END.

 

Commands in this section

 

TCP.Close - Close a TCP client connection.

TCP.LineInput - Read a line of text from a TCP client connection.

TCP.Open - Open a TCP client connection to a server.

TCP.Recv - Receive data from a TCP client connection.

TCP.Send - Send data over a TCP client connection.

 

See also:

 

!HTP-MCP Overview