• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Socket, java.net.UnknownHostException

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic