




已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the License); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * /licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.io.FileOutputStream;import java.util.StringTokenizer;import .telnet.TelnetClient;import .telnet.TelnetNotificationHandler;import .telnet.SimpleOptionHandler;import .telnet.EchoOptionHandler;import .telnet.TerminalTypeOptionHandler;import .telnet.SuppressGAOptionHandler;import .telnet.InvalidTelnetOptionException;/* * This is a simple example of use of TelnetClient. An external option handler * (SimpleTelnetOptionHandler) is used. Initial configuration requested by * TelnetClient will be: WILL ECHO, WILL SUPPRESS-GA, DO SUPPRESS-GA. VT100 * terminal type will be subnegotiated. * * Also, use of the sendAYT(), getLocalOptionState(), getRemoteOptionState() is * demonstrated. When connected, type AYT to send an AYT command to the server * and see the result. Type OPT to see a report of the state of the first 25 * options. * * * author Bruno DAvanzo */public class TelnetClientExample implements Runnable, TelnetNotificationHandler static TelnetClient tc = null;/* * Main for the TelnetClientExample. */public static void main(String args) throws Exception FileOutputStream fout = null;if (args.length 1) System.err.println(Usage: TelnetClientExample1 );System.exit(1);String remoteip = args0;int remoteport;if (args.length 1) remoteport = (new Integer(args1).intValue(); else remoteport = 23;try fout = new FileOutputStream(spy.log, true); catch (IOException e) System.err.println(Exception while opening the spy file: + e.getMessage();tc = new TelnetClient();TerminalTypeOptionHandler ttopt = new TerminalTypeOptionHandler(VT100, false, false, true, false);EchoOptionHandler echoopt = new EchoOptionHandler(true, false, true,false);SuppressGAOptionHandler gaopt = new SuppressGAOptionHandler(true, true,true, true);try tc.addOptionHandler(ttopt);tc.addOptionHandler(echoopt);tc.addOptionHandler(gaopt); catch (InvalidTelnetOptionException e) System.err.println(Error registering option handlers: + e.getMessage();while (true) boolean end_loop = false;try tc.connect(remoteip, remoteport);Thread reader = new Thread(new TelnetClientExample();tc.registerNotifHandler(new TelnetClientExample();System.out.println(TelnetClientExample);System.out.println(Type AYT to send an AYT telnet command);System.out.println(Type OPT to print a report of status of options (0-24);System.out.println(Type REGISTER to register a new SimpleOptionHandler);System.out.println(Type UNREGISTER to unregister an OptionHandler);System.out.println(Type SPY to register the spy (connect to port 3333 to spy);System.out.println(Type UNSPY to stop spying the connection);reader.start();OutputStream outstr = tc.getOutputStream();byte buff = new byte1024;int ret_read = 0;do try ret_read = System.in.read(buff);if (ret_read 0) if (new String(buff, 0, ret_read).startsWith(AYT) try System.out.println(Sending AYT);System.out.println(AYT response:+ tc.sendAYT(5000); catch (IOException e) System.err.println(Exception waiting AYT response: + e.getMessage(); else if (new String(buff, 0, ret_read).startsWith(OPT) System.out.println(Status of options:);for (int ii = 0; ii 0) & (end_loop = false);try tc.disconnect(); catch (IOException e) System.err.println(Exception while connecting:+ e.getMessage(); catch (IOException e) System.err.println(Exception while connecting:+ e.getMessage();System.exit(1);/* * Callback method called when TelnetClient receives an option negotiation * command. * * * param negotiation_code * - type of negotiation command received (RECEIVED_DO, * RECEIVED_DONT, RECEIVED_WILL, RECEIVED_WONT) * * param option_code * - code of the option negotiated * */ Overridepublic void receivedNegotiation(int negotiation_code, int option_code) String command = null;if (negotiation_code = TelnetNotificationHandler.RECEIVED_DO) command = DO; else if (negotiation_code = TelnetNotificationHandler.RECEIVED_DONT) command = DONT; else if (negotiation_code = TelnetNotificationHandler.RECEIVED_WILL) command = WILL; else if (negotiation_code = TelnetNotificationHandler.RECEIVED_WONT) command = WONT;System.out.println(Received + command + for option code + option_code);/* * Reader thread. Reads lines from the TelnetClient and echoes them on the * screen. */ Overridepublic void run() InputStream instr = tc.getInputStream();try byte buff = new byte1024;int ret_read = 0;do ret_read = instr.read(buff);if (r
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 农业技术推广服务责任协议
- 网络工程网络通信理论测试
- 深度学习 课件 第0章-课程简介
- 工程项目管理文献回顾试题及答案
- 投资项目的资金流动分析试题及答案
- 人工智能技术在教育领域的应用合作协议
- 智慧供应链管理 课件 第五章 智慧物流管理
- 2024年固废污染治理项目投资申请报告代可行性研究报告
- 房产小区测试题及答案
- 着眼未来水利水电工程考试试题及答案
- 轮胎式装载机检测报告(共5页)
- 电子设备装接工(高级)理论知识考核试卷一(共11页)
- 毕业设计(论文)玉米育苗制钵机设计(含全套cad图纸)
- 康复评定——感觉功能评定
- 弯矩二次分配法excel表-(1)
- 粉煤灰漂珠粉项目可行性研究报告写作范文
- 华为产品测试策略及验证计划模板
- MPOR涂层测厚仪说明书
- 焊接工艺规程(WPS)
- 医院管理试题学习资料
- 1FC6发电机常见故障的判断及处理方法
评论
0/150
提交评论