Android LAN access problem

  • Thread starter Dirk Bruere at NeoPax
  • Start date
D

Dirk Bruere at NeoPax

I am looking for a computer named "Base" on the LAN However, I cannot
find it and what comes back is an address from my ISP (so Net access is
definitely working). The return is "Base/81.200.64.50". Basically, it
cannot find the name. I'm using the emulator. The code I am using is a
copy of Java code that runs on Windows, and that works fine - returns my
LAN address. What am I missing???

The code is:

InetAddress address = InetAddress.getByName(Constants.serverNameStr);
 
D

Dirk Bruere at NeoPax

The obvious first questions are:

** is your phone Wi-Fi capable? If not, you're out of luck.
** is your phone connected to the mobile data network, or Wi-Fi, and if
Wi-Fi, are you on the same LAN as the computer you're looking for?

Like I said, I'm using the emulator and can clearly access the Net
Everything on the same LAN
One piece of code running on Windows works, identical piece running via
emulator does not
And what's constants.serverNameStr?

"Base"
 
N

Nigel Wade

Like I said, I'm using the emulator and can clearly access the Net
Everything on the same LAN
One piece of code running on Windows works, identical piece running via
emulator does not


"Base"

DNS.

The argument to InetAddress.getByName() should be a hostname. If the
client itself cannot resolve the name to an IP in its local DNS cache it
sends the request to whatever DNS server it is configured to use.

Presumably the Android emulator DNS is not configured the same as the
Windows host.
 
D

Dirk Bruere at NeoPax

DNS.

The argument to InetAddress.getByName() should be a hostname. If the
client itself cannot resolve the name to an IP in its local DNS cache it
sends the request to whatever DNS server it is configured to use.

Presumably the Android emulator DNS is not configured the same as the
Windows host.

Sounds plausible.
Any idea how I set up Eclipse/AndroidSDK/emulator to do the correct lookup?
 
D

Dirk Bruere at NeoPax

AHH!

I wonder how well jCIFS would work on an Android device. It WILL do what
you need to do, and the latest JAR is less than 400K.

A PITA
I have tried setting up WiFi on the emulator but no luck.
Maybe I'll have to actually debug the app on a real device
 
D

Dirk Bruere at NeoPax

bah, you did say that... I am undercaffeinated right now, it's only 9am


Here's what I am trying:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:eek:rientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
<TextView
android:id="@+id/myText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>


package test.inettest;

import java.net.InetAddress;
import java.net.UnknownHostException;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class Activity1 extends Activity {

String myHostname = "testarossa";

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView t = (TextView)findViewById(R.id.myText);
try {
t.setText(InetAddress.getByName(myHostname).toString());
} catch(UnknownHostException exc) {
t.setText("UNKNOWN HOST EXCEPTION");
}
}
}

When I run the app in the emulator, it says UNKNOWN HOST EXCEPTION.

Now, consider that I'm trying to resolve the NetBIOS name of my laptop.
My guess is that Android can't automatically resolve the NetBIOS name of
the computer. Running on the desktop, Java SE will receive the call to
getByName, pass the hostname on to Windows and Windows will pass back
the LAN address. Windows has ability to resolve NetBIOS names. But in an
Android app, there is no built-in facility to resolve NetBIOS hostnames
(as far as I know :>)

If you set serverNameStr to some globally resolvable hostname like
www.google.com or www.lobosstudios.com, what happens?

I *assume* it works, but I'll try it.
I will also try setting "Base" to a static address
(I'm still not sure why you're getting 81.200.64.50, but that's mostly
because I haven't seen your code, other than that one line that you
already gave us)

That's the easy bit.
My router tries to handle the problem by passing it off to my ISP which
returns:
http://advancedsearch.virginmedia.com/
 
P

Paul Cager

This means, most likely, that your ISP could *not* resolve the NetBIOS
name of your computer (not surprising), and returned a default IP
address (the IP of the search page).

My current ISP doesn't do that, but my previous ISP did. It's obnoxious
as hell, but you can't do anything about it.

If the OP is a Virgin Media customer (which looks to be the case),
then he _can_ opt out (somewhere in myvirginmedia.com).

Not that it helps much with the current problem of course ...
 
L

Lew

Steve said:
(e-mail address removed)
The code is:

InetAddress address = InetAddress.getByName(Constants.serverNameStr);

And what's constants [sic].serverNameStr?

If it is a constant, it should be named in accordance with the Java
naming conventions.

If it's not, why are you exposing it directly instead of through an
accessor?
 
D

Dirk Bruere at NeoPax

Steve said:
(e-mail address removed)
The code is:

InetAddress address = InetAddress.getByName(Constants.serverNameStr);

And what's constants [sic].serverNameStr?

If it is a constant, it should be named in accordance with the Java
naming conventions.

It will be
If it's not, why are you exposing it directly instead of through an
accessor?
Because it's a smallish program and I think an accessor for constants is
overkill
 
L

Lew

Dirk said:
It will be

Do you mean that it will be named in accordance with the Java naming
conventions?

DON'T QUOTE SIGS.
Because it's a smallish program and I think an accessor for constants is
overkill

I asked why there's no accessor if it's *not* a constant. Your
answered a different question that I did not ask.
 
D

Dirk Bruere at NeoPax

Do you mean that it will be named in accordance with the Java naming
conventions?

Work out the context yourself and stop being so anal
Who made you Pope of Java?
DON'T QUOTE SIGS.


I asked why there's no accessor if it's *not* a constant. Your
answered a different question that I did not ask.

Well, you got a freebie then
 
L

Lew

Work out the context yourself and stop being so anal
Who made you Pope of Java?

I didn't write the conventions, O Snarky One. They've been around a dozen
years or so in case you hadn't noticed.

Who made you so resistant do doing the right thing, and so snarky about being
corrected, hm?

Take the lesson and stop being a namby-pamby.

Meanwhile you didn't answer my question. What will be what?
 
L

Lew

To be fair, the question has no relevance to the conversation, and I
believe it was a waste of time to ask it in the first place.

I agree, that is your belief.

As for relevance, it's a Java question in an open forum about Java. Pardon
the holy Hell out of me for asking a question you personally did not find
important. I am sooooooo very sorry!
 
D

Dirk Bruere at NeoPax

I didn't write the conventions, O Snarky One. They've been around a
dozen years or so in case you hadn't noticed.

Who made you so resistant do doing the right thing, and so snarky about
being corrected, hm?

Take the lesson and stop being a namby-pamby.

Meanwhile you didn't answer my question. What will be what?
I will get around to tidying up the code in terms of CAPITAL LETTERS
when I get it working
 
D

Dirk Bruere at NeoPax

It doesn't matter, in this case. Go ahead and use your ISP's DNS
servers, but it will not matter.

Why? Because you are trying to resolve a hostname that *will not be
resolvable via the global DNS.*

Think about it. You tried to resolve 'base' and got the address of a
SEARCH PAGE. (at least, that's what I'm assuming
advancedsearch.virginmedia.com is - I can't get there from here)

This means, most likely, that your ISP could *not* resolve the NetBIOS
name of your computer (not surprising), and returned a default IP
address (the IP of the search page).

My current ISP doesn't do that, but my previous ISP did. It's obnoxious
as hell, but you can't do anything about it.

PITA or not, jCIFS *is* your answer. jCIFS speaks NetBIOS.

I have bought an Advent Vega running 2.2 (It's reduced to £200 in PC
World business section online)

Got the USB set up correctly (apparently) for the nVidia Tegra with "adb
devices" returning: "0280410641800117 device" and it appearing in the XP
Device Manager under "Android Phone" as "Android Composite ADB
Interface". Also set the Vega Applications to "USB debugging"
But I cannot get Eclipse to somehow register that the new device exists.
It sees nothing. What am I missing?
 
D

Dirk Bruere at NeoPax

It doesn't matter, in this case. Go ahead and use your ISP's DNS
servers, but it will not matter.

Why? Because you are trying to resolve a hostname that *will not be
resolvable via the global DNS.*

Think about it. You tried to resolve 'base' and got the address of a
SEARCH PAGE. (at least, that's what I'm assuming
advancedsearch.virginmedia.com is - I can't get there from here)

This means, most likely, that your ISP could *not* resolve the NetBIOS
name of your computer (not surprising), and returned a default IP
address (the IP of the search page).

My current ISP doesn't do that, but my previous ISP did. It's obnoxious
as hell, but you can't do anything about it.

PITA or not, jCIFS *is* your answer. jCIFS speaks NetBIOS.

Looking at it now...
Why the **** can't Android do what Windows does - just ask the router DNS?
 
L

Lawrence D'Oliveiro

I will get around to tidying up the code in terms of CAPITAL LETTERS
when I get it working

I wonder why, if constants are supposed to be written in capitals, that
doesn’t apply to class literals?

For instance, “String.class†should be acceptable, nay required, as
“STRING.CLASSâ€.
 
N

Nigel Wade

Why the **** can't Android do what Windows does -

Because Windows uses proprietary (non-standard) mechanisms. Android has
more sense than to tie itself to a Windows-only solution.
just ask the router DNS?

Android does, Windows does not. This is what you are clearly failing to
understand.
 

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

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top