public class Telnet{String host;
int portNum;
public static void main(String[] args){
new Telnet().talkTo(args);
} private void talkTo(String[] args){
if(args.length >= 1)
host = args[0];
else
host = "localhost";
if(args.length >= 2)
portNum = Integer.parseInt(args[1]);
else portNum = 23; System.out.println("Host: " + host + ";port: " + portNum);
try{
Socket s = new Socket(host,portNum); new Pipe(s.getInputStream(),System.out).start(); new Pipe(System.in,s.getOutputStream()).start();
}
catch(IOException e){
System.out.println(e);
return;
}
System.out.println("Connected OK");
}
}
class Pipe extends Thread{
DataInputStream is;
PrintStream os; Pipe(InputStream is,OutputStream os){
this.is = new DataInputStream(is);
this.os = new PrintStream(os);
} public void run(){
String line;
try{
while((line = is.readLine()) != null){
os.print(line);
os.print("\r\n");
os.flush();
}
}
catch(IOException e){
throw new RuntimeException(e.getMessage());
}
}
}
int portNum;
public static void main(String[] args){
new Telnet().talkTo(args);
} private void talkTo(String[] args){
if(args.length >= 1)
host = args[0];
else
host = "localhost";
if(args.length >= 2)
portNum = Integer.parseInt(args[1]);
else portNum = 23; System.out.println("Host: " + host + ";port: " + portNum);
try{
Socket s = new Socket(host,portNum); new Pipe(s.getInputStream(),System.out).start(); new Pipe(System.in,s.getOutputStream()).start();
}
catch(IOException e){
System.out.println(e);
return;
}
System.out.println("Connected OK");
}
}
class Pipe extends Thread{
DataInputStream is;
PrintStream os; Pipe(InputStream is,OutputStream os){
this.is = new DataInputStream(is);
this.os = new PrintStream(os);
} public void run(){
String line;
try{
while((line = is.readLine()) != null){
os.print(line);
os.print("\r\n");
os.flush();
}
}
catch(IOException e){
throw new RuntimeException(e.getMessage());
}
}
}
解决方案 »
- 在线等高手解决~~
- Java EE 的那些事求指教?
- 有谁知道bufferedimage 和 image的区别?
- 关于char问题
- 如何读出字符串中的单个字符?
- 大家给我一些意见啊!!!急.
- jvm在什么时候有机会调用ShutdownHook?为何我addShutdownHook()加进去的善后操作从来没有被执行过?高手请进来解释,拿分
- 关于jdonjive的配置,请高手帮忙!!!!
- 请教一个跟DatabaseMetaData有关的问题?
- 杭电的1005题 Number Sequence 各位帮忙看看
- 有没有规定一定要先安装SDK然后才能安装JVM?否则就安装不了SDK?
- JET的安装目录到底怎样设置
这个我回去试了怎么不行呀!
只可以连接端口但是没有办法。
进行信息交换