getLocalAddress().getHostAddress() returning an empty string

Y

yawnmoth

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!
 
C

Carl

yawnmoth said:
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!

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.
 
Y

yawnmoth

Carl said:
yawnmoth wrote:
<snip>
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?

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?
 
M

Manish Pandit

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
 
Y

yawnmoth

Manish said:
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.
 
M

Manish Pandit

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
 
C

Chris Uppal

yawnmoth said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,270
Messages
2,571,102
Members
48,773
Latest member
Kaybee

Latest Threads

Top