Why i am I getting "Connection refused ":connect error ?

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

    Why i am I getting "Connection refused ":connect error ?

    I just tried to create a small socket application with reference to tutorials on the web..
    Hers's the script for the socket application

    Code:
    package sockets_1;
    import java.net.*;
    import java.io.*;
    
    public class socket_class {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		//test_url();
    		test_socket();
    	}
    	
    	
    	
    	public static void test_socket(){
    		String host="localhost";
    	
    	for (int i=130;i<150;i++){
    		try{
    			Socket sck=new Socket(host,i);
    			System.out.println("Server at "+i+" port");
    		}
    		catch(IOException e){
    			System.err.print(e.getMessage());e.printStackTrace();
    		}
    		
    		}
    }
    }

    When I am running this program,I am getting an error "Connection refused:connect " error for all the port numbers in the range except for port number 135 which is the TCP/IP... Sometimes it also prints the error " No buffer space available (maximum connections reached?): JVM_Bind"....
    I am somewhat unfamiliar wd thoses error and I googled as well but couldn't extract musch from it...
    What do those errors exactly mean and why I am able to create a socket a only 1 port???


    Thans in adv
    Last edited by Niheel; Jun 25 '10, 02:13 PM. Reason: please use code tags when asking questions with code
  • Dheeraj Joshi
    Recognized Expert Top Contributor
    • Jul 2009
    • 1129

    #2
    It is always good practice to use ports 1025 or above.
    All the ports 0 - 1024 are used by OS.

    Just to make sure nobody is using 135th port. Use
    Code:
    netstat -a | grep 135
    Regards
    Dheeraj Joshi

    Comment

    • phpuser123
      New Member
      • Dec 2009
      • 108

      #3
      Thanks for the prompt replyy...
      I tried using a range of ports of 1030 to 1200
      and the result nearly turned out to be the same....
      Here I am pasting the error

      Connection refused: connectjava.net .ConnectExcepti on: Connection refused: connect
      at java.net.PlainS ocketImpl.socke tConnect(Native Method)
      at java.net.PlainS ocketImpl.doCon nect(Unknown Source)
      at java.net.PlainS ocketImpl.conne ctToAddress(Unk nown Source)
      at java.net.PlainS ocketImpl.conne ct(Unknown Source)
      at java.net.SocksS ocketImpl.conne ct(Unknown Source)
      at java.net.Socket .connect(Unknow n Source)
      at java.net.Socket .connect(Unknow n Source)
      at java.net.Socket .<init>(Unknow n Source)
      at java.net.Socket .<init>(Unknow n Source)
      at sockets_1.socke t_class.test_so cket(socket_cla ss.java:41)
      at sockets_1.socke t_class.main(so cket_class.java :13)

      Comment

      • Dheeraj Joshi
        Recognized Expert Top Contributor
        • Jul 2009
        • 1129

        #4
        Are you sure nobody is using ports between 1030-1200?

        Regards
        Dheeraj Joshi

        Comment

        • phpuser123
          New Member
          • Dec 2009
          • 108

          #5
          Originally posted by dheerajjoshim
          Are you sure nobody is using ports between 1030-1200?

          Regards
          Dheeraj Joshi
          Thanks,your post was quite useful to me ...
          Atually,my pc had caught a virus and if I am nt wrong this was what was the problem....
          the virus has equipped the sockets...
          Alteast now I know what had beeen wrong ...

          Comment

          Working...