当前位置: 技术问答>java相关
100分!各位看看这个java实现的telnet客户端怎么不对阿!!
来源: 互联网 发布时间:2017-04-26
本文导语: import java.net.*;import java.io.*;public class JTelnetC { Socket sock; public JTelnetC(String h, int p){ try { sock = new Socket(h, p); new InputPipe(sock.getOutputStream()).start(); new OutputPipe(sock).start(); } catch(IOException e) { System.out.println(e); ...
import java.net.*;import java.io.*;public class JTelnetC { Socket sock; public JTelnetC(String h, int p){ try { sock = new Socket(h, p); new InputPipe(sock.getOutputStream()).start(); new OutputPipe(sock).start(); } catch(IOException e) { System.out.println(e); return; }}public class InputPipe extends Thread { DataInputStream is; PrintStream os;public InputPipe(OutputStream os){ this.is = new DataInputStream(System.in); this.os = new PrintStream(os);}public void run() { String line; try { while(true) { line = is.readLine(); os.print(line); os.print("rn"); os.flush(); } } catch(IOException e) { throw new RuntimeException(e.getMessage()); }}}public class OutputPipe extends Thread { InputStream in; OutputStream ot; PrintStream os;public OutputPipe(Socket sock){ try { this.ot = sock.getOutputStream(); this.in = sock.getInputStream(); this.os = new PrintStream(System.out); } catch(IOException e) { System.out.println(e); }}public void run(){ String line; int i; try { while(true) { i = in.read(); if (i == 255) { int i1 = in.read(); int i2 = in.read(); tel_net(i1,i2); } else { os.print((char)i); os.flush(); } } } catch(IOException e) { throw new RuntimeException(e.getMessage()); }}private void tel_net(int i1, int i2){ int i = i1; if (i == 253) { i = i2; if (i == 1) wont(i); else if (i == 24) wont(i); else if (i == 31) wont(i); else if (i == 35) wont(i); else if (i == 36) wont(i); else if (i == 39) wont(i); }}private void wont(int i){ try { ot.write(255); ot.write(252); ot.write(i); } catch (IOException e) { System.out.println(e); }}} public static void main(String args[]) { String host = "171.103.2.142"; int port = 23; new JTelnetC(host, port);}}
|
我怀疑是你的协议处理方面出了问题:
仔细审查一下,及相关函数的代码
...
if (i == 255)
{
int i1 = in.read();
int i2 = in.read();
tel_net(i1,i2);
... }
我这里没有协议资料,不便多言
通信方面应该没有什么问题
仔细审查一下,及相关函数的代码
...
if (i == 255)
{
int i1 = in.read();
int i2 = in.read();
tel_net(i1,i2);
... }
我这里没有协议资料,不便多言
通信方面应该没有什么问题
|
有神莫问题
|
up
|
提示什么错误?
|
gz
|
gz