微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

tConsole Telnet 开发环境

程序名称:tConsole

授权协议: 未知

操作系统: 跨平台

开发语言: Java

tConsole 介绍

tConsole 是一个 Telnet Console 框架,提供一个 Telnet 环境支持,给予没有界面类的应用一个可以通过命令行进行交互的工具。

特性

  1. 支持监听本地端口提供 Telnet 交互的界面。
  2. 支持基于标准输入输出构建交互控制台的能力。
  3. 利用 tConsole 可以轻松构建命令工具包。

样例

实现一个控制台命令。

**public** **class** **HelloWordExecutor** **implements** **TelExecutor** {
    /** 命令的帮助信息,在 help <command> 时候输出这个信息 */
    **public** **String** **helpInfo** () {
        **return** "hello help.";  
    }
    /** 执行命令体 */
    **public** **String** **doCommand** ( **TelCommand** telCommand) **throws** **Throwable** {
        **return** "you say ->" + telCommand.getCommandName();
    }
}

利用 telnet 命令来交互

**public** **static** **void** **main** ( **String** [] args) {
    **AppContext** appContext = **Hasor**.create().build(( **TelModule** ) apiBinder -> {
        **TelnetBuilder** telnetBuild = apiBinder.asTelnet("127.0.0.1", 2180);
        telnetBuild.addExecutor("hello").to( **HelloWordExecutor**.class);
    }
    appContext.joinSignal();
}

输入 telnet 127.0.0.1 2180 之后

>telnet 127.0.0.1 2180
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
--------------------------------------------

Welcome to tConsole!

     login : Tue Jan 07 14:26:29 CST 2020 Now. form /127.0.0.1:60023
    workAt : /127.0.0.1:2180
Tips: You can enter a 'help' or 'help -a' for more @R_668_4045@ion.
use the 'exit' or 'quit' out of the console.
--------------------------------------------
tConsole>

充当命令工具包,建议利用 Spring Boot 的 fat jar 打包能力整合使用。

**public** **static** **void** **main** ( **String** [] args) {
    **AppContext** appContext = **Hasor**.create().build(( **TelModule** ) apiBinder -> {
        **HostBuilder** hostBuild = apiBinder.asHostWithSTDO().preCommand(args);
        hostBuild.addExecutor("hello").to( **HelloWordExecutor**.class);
    }
}

输入 java xxx.jar hello 执行 hello 命令。

tConsole 官网

https://gitee.com/zycgit/hasor/tree/master/hasor-tconsole

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐