高手帮忙(java 的telnet)

snafor 2003-08-19 06:17:31
不知道那位高手有java 的telnet客用端
原代码,小弟讨要一份。
Email:jone1934531@163.com

谢谢
...全文
33 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
snafor 2003-08-23
  • 打赏
  • 举报
回复
晕!。。
这个我回去试了怎么不行呀!
只可以连接端口但是没有办法。
进行信息交换
snafor 2003-08-21
  • 打赏
  • 举报
回复
谢谢
star821116 2003-08-20
  • 打赏
  • 举报
回复
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());
}
}
}

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧