java,socket,,ports

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phpuser123
    New Member
    • Dec 2009
    • 108

    java,socket,,ports

    public static void test_socket(){
    String host="localhost ";
    for (int i=0;i<50;i++){
    try{
    Socket sc=new Socket(host,i);
    System.out.prin tln("There is a server at port "+i+" ");
    }
    catch(UnknownHo stException e){
    System.out.prin tln("Host There is an error at port "+i+" ");
    }
    catch(IOExcepti on e){
    System.out.prin tln("IO There is an error at port "+i+" ");
    }
    }
    }



    I just copied and executed theses codes from the net...
    All the times ,I am getting the IOException ....What's the problem with my codes,Why am I getting this exception all the time???


    Thanks in adv
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    Not entirely sure. Is there a specific purpose to opening this port? You may want to use a Connection or ClientConnectio n object instead.

    Comment

    Working...