Question:
java network program error?
?
2009-11-29 07:28:34 UTC
import java.net.*;
import java.io.*;
class Whois {
public static void main(String args[]) throws Exception {
int c;
Socket s = new Socket("internic.net", 43);
InputStream in = s.getInputStream();
OutputStream out = s.getOutputStream();
String str = (args.length ==0? "osborne.com" : args[0]) + "\n";
byte buf[] = str.getBytes();
out.write(buf);
while ((c = in.read()) != -1) {
System.out.print((char) c);
}
s.close();
}
}



error encountered when i run this program
C:\>java Whois
Exception in thread "main" java.net.ConnectException: Connection refused: connec
t
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(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.(Unknown Source)
at java.net.Socket.(Unknown Source)
at Whois.main(Whois.java:7)
Three answers:
om
2009-11-29 11:29:45 UTC
That means that no server is listening on port 43 of the "internic.net" server. There's nothing there to accept your connection, so the server will refuse your connection attempt.



This is a consequence of the server's condition. It's not caused a defect in your program. You would get exactly the same result if you tried to 'telnet' to "internic.net" port 43. Your program could handle the condition more gracefully but it can't change the outcome.



If you want to contact a server that wll accept connections on port 43 then change the server name in your program from "internic.net" to "whois.internic.net".
parth m
2009-11-30 03:44:15 UTC
The answer given by om is correct. However, the server may also have a firewall that is blocking the connection to this port. I tried "whois.internic.net:43" on my browser I got





"Port Restricted for Security Reasons" error. Please check that the server has this port open for your client machine to use.
?
2016-10-03 13:21:08 UTC
here 3 strains make no experience: int oneLength = wordListOne = wordListOne.length; int twoLength = wordListTwo = wordListTwo.length; int threeLength = wordListThree = wordListThree.length; Are you specific that's what it says in the e book? i could think of it would be: int oneLength = wordListOne.length; int twoLength = wordListTwo.length; int threeLength = wordListThree.length;


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...