隨筆 - 303  文章 - 883  trackbacks - 0
          <2007年3月>
          25262728123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          歡迎光臨! 
          閑聊 QQ:1074961813

          隨筆分類(357)

          我管理的群

          公共blog

          • n維空間
          • Email : java3d@126.com 群 : 12999758

          參與管理的論壇

          好友的blog

          我的其他blog

          朋友的網站

          搜索

          •  

          最新評論

          old urls : http://www.jscape.com/inetfactory/telnet.html

          Code Example

          ??1 /*
          ??2 ?*?@(#)TelnetExample.java
          ??3 ?*
          ??4 ?*?Copyright?(c)?2001-2002?JScape
          ??5 ?*?1147?S.?53rd?Pl.,?Mesa,?Arizona,?85206,?U.S.A.
          ??6 ?*?All?rights?reserved.
          ??7 ?*
          ??8 ?*?This?software?is?the?confidential?and?proprietary?information?of
          ??9 ?*?JScape.?("Confidential?Information").??You?shall?not?disclose?such
          ?10 ?*?Confidential?Information?and?shall?use?it?only?in?accordance?with
          ?11 ?*?the?terms?of?the?license?agreement?you?entered?into?with?JScape.
          ?12 ? */

          ?13
          ?14 import ?com.jscape.inet.telnet. * ;
          ?15 import ?java.io. * ;
          ?16
          ?17 public ? class ?TelnetExample? extends ?TelnetAdapter? {
          ?18
          ?19 ?? private ?Telnet?telnet? = ? null ;
          ?20 ?? private ?OutputStream?output? = ? null ;
          ?21 ?? private ? static ?BufferedReader?reader? = ? null ;
          ?22 ?? private ? boolean ?connected? = ? false ;
          ?23
          ?24 ?? public ?TelnetExample(String?hostname)? throws ?IOException? {
          ?25
          ?26 ????String?input? = ? null ;
          ?27 ???? // ?create?new?Telnet?instance
          ?28 ????telnet? = ? new ?Telnet(hostname);
          ?29
          ?30 ???? // ?register?this?class?as?TelnetListener
          ?31 ????telnet.addTelnetListener( this );
          ?32
          ?33 ???? // ?establish?Telnet?connection
          ?34 ????telnet.connect();
          ?35 ????connected? = ? true ;
          ?36
          ?37 ???? // ?get?output?stream
          ?38 ????output? = ?telnet.getOutputStream();
          ?39
          ?40 ???? // ?sends?all?data?entered?at?console?to?Telnet?server
          ?41 ???? while ?((input? = ?reader.readLine())? != ? null )? {
          ?42 ?????? if ?(connected)? {
          ?43 ????????((TelnetOutputStream)?output).println(input);
          ?44 ??????}
          ? else ? {
          ?45 ???????? break ;
          ?46 ??????}

          ?47 ????}

          ?48 ??}

          ?49
          ?50 ?? /** ?Invoked?when?Telnet?socked?is?connected.
          ?51 ???*? @see ?TelnetConnectedEvent
          ?52 ???*? @see ?Telnet#connect
          ?53 ??? */

          ?54 ?? public ? void ?connected(TelnetConnectedEvent?event)? {
          ?55 ????System.out.println( " Connected " );
          ?56 ??}

          ?57
          ?58 ?? /** ?
          ?59 ???*?Invoked?when?Telnet?socket?is?disconnected.?Disconnect?can
          ?60 ???*?occur?in?many?circumstances?including?IOException?during?socket?read/write.
          ?61 ???*? @see ?TelnetDisconnectedEvent
          ?62 ???*? @see ?Telnet#disconnect
          ?63 ??? */

          ?64 ?? public ? void ?disconnected(TelnetDisconnectedEvent?event)? {
          ?65 ????connected? = ? false ;
          ?66 ????System.out.print( " Disconnected.??Press?enter?key?to?quit. " );
          ?67 ??}

          ?68
          ?69 ?? /**
          ?70 ???*?Invoked?when?Telnet?server?requests?that?the?Telnet?client?begin?performing?specified?<code>TelnetOption</code>.
          ?71 ???*? @param ?event?a?<code>DoOptionEvent</code>
          ?72 ???*? @see ?DoOptionEvent
          ?73 ???*? @see ?TelnetOption
          ?74 ??? */

          ?75 ?? public ? void ?doOption(DoOptionEvent?event)? {
          ?76 ???? // ?refuse?any?options?requested?by?Telnet?server
          ?77 ????telnet.sendWontOption(event.getOption());
          ?78 ??}

          ?79
          ?80 ?? /**
          ?81 ???*?Invoked?when?Telnet?server?offers?to?begin?performing?specified?<code>TelnetOption</code>.
          ?82 ???*? @param ?event?a?<code>WillOptionEvent</code>
          ?83 ???*? @see ?WillOptionEvent
          ?84 ???*? @see ?TelnetOption
          ?85 ??? */

          ?86 ?? public ? void ?willOption(WillOptionEvent?event)? {
          ?87 ???? // ?refuse?any?options?offered?by?Telnet?server
          ?88 ????telnet.sendDontOption(event.getOption());
          ?89 ??}

          ?90
          ?91 ?? /**
          ?92 ???*?Invoked?when?data?is?received?from?Telnet?server.
          ?93 ???*? @param ?event?a?<code>TelnetDataReceivedEvent</code>
          ?94 ???*? @see ?TelnetDataReceivedEvent
          ?95 ??? */

          ?96 ?? public ? void ?dataReceived(TelnetDataReceivedEvent?event)? {
          ?97 ???? // ?print?data?recevied?from?Telnet?server?to?console
          ?98 ????System.out.print(event.getData());
          ?99 ??}

          100
          101 ?? /**
          102 ???*?Main?method?for?launching?program
          103 ???*? @param ?args?program?arguments
          104 ??? */

          105 ?? public ? static ? void ?main(String[]?args)? {
          106 ???? try ? {
          107 ??????reader? = ? new ?BufferedReader( new ?InputStreamReader(System.in));
          108
          109 ?????? // ?prompt?user?for?Telnet?server?hostname
          110 ??????System.out.print( " Enter?Telnet?server?hostname?(e.g.?10.0.0.1):? " );
          111 ??????String?hostname? = ?reader.readLine();
          112
          113 ?????? // ?create?new?TelnetExample?instance
          114 ??????TelnetExample?example? = ? new ?TelnetExample(hostname);
          115 ????}
          ? catch ?(Exception?e)? {
          116 ??????e.printStackTrace(System.out);
          117 ????}

          118 ??}

          119
          120 }
          ?


          地震讓大伙知道:居安思危,才是生存之道。
          posted on 2007-03-25 16:38 小尋 閱讀(557) 評論(0)  編輯  收藏 所屬分類: j2se/j2ee/j2me
          主站蜘蛛池模板: 开远市| 五台县| 遂平县| 隆回县| 太谷县| 深圳市| 安康市| 德州市| 友谊县| 衡阳县| 凤凰县| 龙岩市| 福鼎市| 武乡县| 蓝田县| 景德镇市| 徐水县| 黔东| 三穗县| 定州市| 宜章县| 芮城县| 沙洋县| 丰宁| 青冈县| 金阳县| 花莲县| 临澧县| 哈巴河县| 调兵山市| 内黄县| 南雄市| 文登市| 井冈山市| 宁化县| 通山县| 哈尔滨市| 开原市| 静安区| 教育| 随州市|