Skip to content

Latest commit

 

History

History
104 lines (78 loc) · 1.88 KB

README_en.md

File metadata and controls

104 lines (78 loc) · 1.88 KB

中文|English

Telnet

Telnet client implemented in dart language.

Features

  • Negotiation.
  • TLS support.
  • Event listening.
  • Enumerate all Telnet commands and options.

Usage

Create a Telnet connection task.

// Ordinary
final task = TelnetClient.startConnect(
  host: host, 
  port: port, 
  timeout: timeout,
  onError: onError,
  onDone: onDone,
  onEvent: onEvent,
);

// Secure
final task = TelnetClient.startSecureConnect(
	host: host,
  port: port,
  timeout: timeout,
  onError: onError,
  onDone: onDone,
  onEvent: onEvent,
  securityContext: securityContext,
  supportedProtocols: supportedProtocols,
  onBadCertificate: onBadCertificate,
);

Wait the connection task completed and get the TelnetClient instance.

// Sync
await task.waitDone();
final client = task.client;
final connected = client != null;

// Async
task.onDone = (client) {
  final connected = client != null;
}

Cancel the connection task.

task.cancel();

Close the TelnetClient.

client.terminate();

Listen and handle events.

final task = TelnetClient.startConnect(
  host: host, 
  port: port, 
  onEvent: (client, event) {
    final eventType = event.type;
    final eventMsg = event.msg;
    
    if (eventType == TLMsgEventType.write) {
      print("This is write event. Data flows from the client to the server.");
    } else if (eventType == TLMsgEventType.read) {
      print("This is write event. Data flows from the server to the client.");
    }
    
    if (eventMsg is TLOptMsg) {
      // Negotiation.
      print("IAC ${eventMsg.cmd.code} ${eventMsg.opt.code}");
    } else if (eventMsg is TLSubMsg) {
      // Subnegotiation.
      print("IAC SB ${eventMsg.opt.code} ${eventMsg.arg.join(' ')} IAC SE");
    } else if (eventMsg is TLTextMsg) {
      // String message.
      print(eventMsg.text);
    }
  },
);