aspose file tools*
The moose likes I/O and Streams and the fly likes Socket, java.net.UnknownHostException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Socket, java.net.UnknownHostException " Watch "Socket, java.net.UnknownHostException " New topic
Author

Socket, java.net.UnknownHostException

Andrew Lowcock
Greenhorn

Joined: Aug 13, 2003
Posts: 8
I've got a big problem.
I've have an FTP class that opens a connection to a remote machine, that has been used many times and works well in production. However ....
I've recently used the FTP component in another application which I need to show to clients, and I get java.net.UnknownHostException when passing an IP address in as the parameter - this works fine on my Win2k dev machine, and the destination IP is that of another Win2k machine.
The code fails on a Linux machine (I can however use the account under which the application is run to manually establish a connection to the FTP server as I would expect)
Could anyone please suggest where I could start looking for the problem? I am really at a loss. Apologies if this is the wrong forum. Here is the stack trace.
Many thanks (I've posted this to advanced topics also - sorry for the duplication)
Exception Trace:
java.net.UnknownHostException: rdan
at java.net.InetAddress.getAllByName0(InetAddress.java:571)
at java.net.InetAddress.getAllByName0(InetAddress.java:540)
at java.net.InetAddress.getByName(InetAddress.java:449)
at java.net.Socket.<init>(Socket.java:100)
at com.companyxxxxx.ftp.FTPControlSocket.<init>(FTPControlSocket.java:78)
at com.companyxxxxx.ftp.FTPControlSocket.<init>(FTPControlSocket.java:63)
at com.companyxxxxx.ftp.FTPClient.<init>(FTPClient.java:79)
at com.companyxxxxx.intranet.candidatexmlimportproofing.servlet.forms.EditCandidateServlet.ftpFiles(EditCandidateServlet.java:547)
at com.companyxxxxx.intranet.candidatexmlimportproofing.servlet.forms.EditCandidateServlet.doPost(EditCandidateServlet.java:193)
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30

OK, well, duplication aside, I'm glad you posted this, because the new information is very useful. Look at that stack trace: Java's clearly trying to lookup a host named "rdan"

I looked at the JDK source; these classes haven't changed in a long time so even without knowing what Java version you're using I can see what's going on.
The important line is InetAddress.java line 449:

Anyway, you can see that this is being passed a host name, not an IP address, as you assert -- it doesn't start with a number. If you look at the Socket constructor at line 100, you'll see it's just

So without any shadow of a doubt, your code is passing the host name to a Socket constructor, not the dotted-quartet IP address, and the Linux box can't look up the hostname. Check your code!
A quick fix, by the way, could be to add the host "rdan" to the /etc/hosts file.


[Jess in Action][AskingGoodQuestions]
Andrew Lowcock
Greenhorn

Joined: Aug 13, 2003
Posts: 8
OK I solved this - I simply needed to .trim() the ip address that I obtained from the database. This extra white space seemed to be ignored on Win2k, but not on Linux....
Cheers
Andrew
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Socket, java.net.UnknownHostException
 
Similar Threads
GZIPing JSP
Error setting up SocketClientInvoker - unknown host in clustered env
scoured the net for reusable ftp program but having problems
Remote EJB URL Issue
java.net.UnknownHostException