• Post Reply Bookmark Topic Watch Topic
  • New Topic

Socket, java.net.UnknownHostException  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Andrew Lowcock
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Something must be done about this. Let's start by reading this tiny ad:
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!