1. tConsoleTelnet 開發(fā)環(huán)境

        聯(lián)合創(chuàng)作 · 2023-09-30 19:50

        tConsole 是一個 Telnet Console 框架,提供一個 Telnet 環(huán)境支持,給予沒有界面類的應(yīng)用一個可以通過命令行進行交互的工具。

        特性

        1. 支持監(jiān)聽本地端口提供 Telnet 交互的界面。
        2. 支持基于標(biāo)準(zhǔn)輸入輸出構(gòu)建交互控制臺的能力。
        3. 利用 tConsole 可以輕松構(gòu)建命令工具包。

        樣例

        實現(xiàn)一個控制臺命令。

        public class HelloWordExecutor implements TelExecutor {
            /** 命令的幫助信息,在 help <command> 時候輸出這個信息 */
            public String helpInfo() {
                return "hello help.";  
            }
            /** 執(zhí)行命令體 */
            public String doCommand(TelCommand telCommand) throws Throwable {
                return "you say ->" + telCommand.getCommandName();
            }
        }

        Server 模式

        利用 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 information.
        use the 'exit' or 'quit' out of the console.
        --------------------------------------------
        tConsole>

        Host 模式

        充當(dāng)命令工具包,建議利用 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 執(zhí)行 hello 命令。

        瀏覽 28
        點贊
        評論
        收藏
        分享

        手機掃一掃分享

        編輯 分享
        舉報
        評論
        圖片
        表情
        推薦
        點贊
        評論
        收藏
        分享

        手機掃一掃分享

        編輯 分享
        舉報
          
          

            1. 91福利国产成人精品播放 | 黄色视频在线免费播放 | 日韩欧美视频一区二区 | 91香蕉污 | 公车乱伦|