我运行一个简单的whois程序,就是从whois网站查询输入的地址是否被注册过,但是为什么运行后总是出现超时的问题呢,这个现象是指已经链接上了吗?还是根本就没有链接上?那个网站我试过,是可以使用的网站,我觉得很奇怪啊,很简单的为什么不通呢,帮帮我吧,谢谢了import java.net.*;
import java.io.*;public class whois
{
public final static int port = 43;
public final static String hostname = "218.30.103.154";
public static void main(String[] args)
{
Socket theSocket;
DataInputStream theWhoisStream;
PrintStream ps;//检查命令行参数
if (args.length <1)
{
System.out.println("\nUsage: java whois <command>");
System.out.println("Parameters:");
System.out.println(
"\tcommand = one or more Domain name, or other command.");
System.out.println("Example:");
System.out.println("\tjava whois sohu.com");
System.out.println("\tjava whois help");System.exit(1); //退出
}
while(true)
{
try {//在TCP服务端口43(十进制)连接SRI-NIC服务主机
theSocket = new Socket("218.30.103.154", port);
System.out.println("Socket connected!");
ps = new PrintStream(theSocket.getOutputStream());
//发送用户提供的一个或多个命令
for (int i = 0; i < args.length; i++)
ps.print(args[i] + " ");
//以回车和换行(<CRLF>)结尾
ps.print("\r\n");//接受相应命令的返回信息
theWhoisStream = new DataInputStream(theSocket.getInputStream());
String s;
while ((s = theWhoisStream.readLine()) != null) {
System.out.println(s);
}//关闭DataInputStream和PrintWriter
theWhoisStream.close();
ps.close();
//关闭socket
theSocket.close();
break;
}
catch (IOException e) {
System.err.println(e);
continue;
}
}
}
}

解决方案 »

  1.   

    说明一个问题,你说如的IP和PORT你不能访问
      

  2.   

    谢谢你,不过我换了一个服务器地址198.41.0.6是没错的,我查过了,port是whois的专用端口啊怎么回事呢
      

  3.   

    theSocket都没有accept(),怎么可能连上
      

  4.   

    支持楼上的,accept,监听连接请求
      

  5.   

    不过我用telnet去远程登录 whois服务器,总是登不上,端口就是43号,是不是whois服务器有什么权限啊?
      

  6.   

    我这个是客户端程序啊,服务器端是whois数据库,怎么会用到accept()呢?这不是服务器端的方法吗