k.net.telnetClient
Telnet sessions
| Execution Context | Prerequisites | Typical Use |
|---|---|---|
| KScript API, background jobs | Reachable host and port speaking plain TCP/Telnet | SMTP/text-protocol probing and legacy device command interaction |
k.net.telnetClient.connect establishes a Telnet connection and reads and writes terminal data inside the callback via ConnectedClient.
Quick Start
js
let reply = ""
k.net.telnetClient.connect("smtp.example.com", 25, (client) => {
client.terminatedRead("\r\n", 10)
client.writeLine("NOOP")
reply = client.read(10)
}, 30)
return { reply }Quick Reference
| Method / Property | Description | Returns |
|---|---|---|
connect(host, port, callback[, timeout]) | Connect to a Telnet host and port and run callback | void |
client.write(command) | Write raw command text without a trailing newline | void |
client.writeLine(command) | Write command text followed by a newline | void |
client.read([timeout]) | Read available output | string |
client.terminatedRead(terminator[, timeout]) | Read output until a matching terminator is reached | string |
connect()
Connect to a host and port and run interactive reads/writes via ConnectedClient; the session closes when the callback finishes.
Exceptions are swallowed silently
Unlike sshClient and sftpClient, k.net.telnetClient.connect() catches and silently ignores all connection, timeout, and callback exceptions without throwing or returning an error status. Track completion with a flag set inside callback when failure detection is needed.
| Parameter | Type | Required | Description |
|---|---|---|---|
host | string | Yes | Telnet host name or IP |
port | number | Yes | Port |
callback | (client) => void | Yes | Session callback after connecting |
timeout | number | No | Timeout in seconds; default is 30 |
Returns: void.
js
let completed = false
k.net.telnetClient.connect(host, port, (client) => {
client.writeLine("help")
const text = client.read(10)
completed = true
}, 30)ConnectedClient
Terminal I/O object passed to the connect() callback.
| Method | Parameters | Returns | Description |
|---|---|---|---|
write(command) | command: string | void | Send a command |
writeLine(command) | command: string | void | Send a command line |
read(timeout?) | timeout?: number | string | Read output |
terminatedRead(terminator, timeout?) | terminator: string, timeout?: number | string | Read until a terminator is found |
js
let hello = ""
let response = ""
k.net.telnetClient.connect("smtp.example.com", 25, (client) => {
hello = client.terminatedRead("\r\n", 10)
client.writeLine("HELO kooboo.local")
response = client.read(10)
})
return { hello, response }TypeScript Definitions
ts
interface TelnetClient {
connect(host: string, port: number, callback: (p1: ConnectedClient) => void, timeout?: number): void;
}
interface ConnectedClient {
terminatedRead(terminator: string, timeout?: number): string;
read(timeout?: number): string;
write(command: string): void;
writeLine(command: string): void;
}