Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

getLocalAddress().getHostAddress() returning an empty string

Thread view: 
yawnmoth - 17 Nov 2006 18:00 GMT
Say I have the following:

(new Socket("some domain", 80).getLocalAddress().getHostAddress()

Are there conditions under which that can return an empty string?  I
ask because I have a script that does that, among other things, and I
have some people telling me that it's not working for them - that it's
returning the empty string for them.

Any ideas would be appreciated - thanks!
Carl - 17 Nov 2006 20:25 GMT
> Say I have the following:
>
[quoted text clipped - 6 lines]
>
> Any ideas would be appreciated - thanks!

yawnmoth,

It would be easier to try to help if you post the code in context,
based on only this line it is hard to even guess what the problem is.
Are you sure the Socket is being successfully instantiated and not
throwing some exception?

Carl.
yawnmoth - 17 Nov 2006 21:17 GMT
> <snip>
> yawnmoth,
[quoted text clipped - 3 lines]
> Are you sure the Socket is being successfully instantiated and not
> throwing some exception?

Here's the context:

import java.applet.*;
import java.net.*;

public class HttpRequestor extends Applet
{
    public void start()
    {
        try
        {
            Socket sock = new Socket(getParameter("domain"),
Integer.parseInt(getParameter("port")));
            String path =
getParameter("path")+"&local="+sock.getLocalAddress().getHostAddress();
            String httpRequest = "GET "+path+" HTTP/1.0\r\nHost:
"+getParameter("domain")+"\r\n\r\n";
            sock.getOutputStream().write(httpRequest.getBytes());
            sock.getInputStream();
        }
        catch (Exception e)
        {
            //e.printStackTrace();
        }
    }
}

The Socket is clearly being created since, if it weren't, I wouldn't
get the HTTP request.

Is it possible that getLocalAddress().getHostAddress() simply doesn't
work on all versions of the JRE?
Manish Pandit - 17 Nov 2006 22:18 GMT
You're opening a connection from an Applet - Is this a trusted applet,
and is the server on which you're opening the port on the Applet host?

-cheers,
Manish
yawnmoth - 18 Nov 2006 00:46 GMT
> You're opening a connection from an Applet - Is this a trusted applet,
> and is the server on which you're opening the port on the Applet host?
Yes to the latter.  With regard to the former...  what is a trusted
applet vs. an untrusted one?

That said, in an attempt to diagnose this problem, I've started logging
requests made to the server side script, and while, most of the time,
the local parameter is set, it isn't always.

The fact, however, that an entry exists in the log at all suggests that
the request was made successfully.
Manish Pandit - 18 Nov 2006 05:52 GMT
I believe a trusted applet can make connections outside of the host it
originated from. You can google it out for more info.

Another thing I noticed - can you uncomment the exception handling
part, so you can see if there is one being thrown?

-cheers,
Manish
Chris Uppal - 18 Nov 2006 17:02 GMT
> Is it possible that getLocalAddress().getHostAddress() simply doesn't
> work on all versions of the JRE?

It doesn't appear to be possible for 1.4 or 1.5 to return an empty string
(judging by the source to the concrete subclasses of InetAddress: Inet4Address
and Inet6Address).

But what, say, the antediluvian MS JVM (or rather: "J"VM) does is anybody's
guess.

   -- chris


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.