JDK1.4Socket s = new Socket();
s.connect(new InetSocketAddress(host,port), timeout);  //可以设置连接超时

解决方案 »

  1.   

    搂主,你的代码根本有问题嘛!!
    inLine=in.readLine();
        while( inLine!=null )
        {
          System.out.println(inLine);
        }
    你这样只要inLine读进来不是null,岂不要死循环了?应该改成:
    while((inLine=in.readLine())!=null){
      //....
    }
    吧。
      

  2.   

    sock client缺省还是阻塞的,即便你用socketchannel,所以你一定要显示的     SocketChannel sc = SocketChannel.open();
          sc.configureBlocking(false);
                 sc.connect(new InetSocketAddress(InetAddress.getByName(host), port));             int myPatience = 5;
        while ((!sc.finishConnect()) && (myPatience-- >0)) {
            System.out.println("I am waiting ...");
                     //sleep(400);
        }