Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Soket connection failure

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    14
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Post Soket connection failure

    Hi Coders...
    I am new to socket Programming ..I wrote my first program to connect to internic using socket . i am using wifi.plz guide me .here is my code:
     
    int c;
    		Socket s=new Socket("internic.net",43);
    		InputStream in=s.getInputStream();
    		OutputStream out=s.getOutputStream();
    		String str="uet.edu.pk";
    		byte buf[]=str.getBytes();
    		out.write(buf);
    		// Send request.
    		out.write(buf);
    		// Read and display response.
    		while ((c = in.read()) != -1) {
    		System.out.print((char) c);
    		}
    		s.close();
     
    	}

    output is:

    Exception in thread "main" java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Un known Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress( Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at Whois.main(Whois.java:13)


  2. #2
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: Soket connection failure

    Hello.
    I would suggest check if the internet connection is on.
    If yes then verify if the url and the port number are valid.

    Thanks,
    Syed.

  3. #3
    Junior Member
    Join Date
    Jul 2013
    Posts
    14
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Soket connection failure

    Net connection confirmed on.Changed the name but still of no gain

  4. #4
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: Soket connection failure

    Hi.
    I just checked the socket creation.
    Connection is getting refused.
    Please check if the internic.net is providing connection service at port 43. If yes then it may require authentication. I mean username and password.

    Thanks,
    Syed.

Similar Threads

  1. Else-if statment failure
    By tyb97 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: September 17th, 2011, 08:52 PM
  2. Replies: 12
    Last Post: September 3rd, 2011, 07:07 AM
  3. [SOLVED] changing datatype failure
    By fartofagony in forum What's Wrong With My Code?
    Replies: 11
    Last Post: September 2nd, 2011, 05:14 PM
  4. [SOLVED] JSCH Auth Failure
    By techwiz24 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 30th, 2011, 05:17 PM
  5. Replies: 0
    Last Post: March 26th, 2011, 11:07 AM