سؤال

Well, tried the following bit of code:

import jcifs.netbios.NbtAddress;
...

              try{
                  NbtAddress addr = NbtAddress.getByName("Base");
              }catch (UnknownHostException e){}
...

And it throws that exception. Any ideas? I have tried it with a couple of named machines on the LAN

هل كانت مفيدة؟

المحلول 2

I was using the emulator. When I ran the app on real hardware the problem disappeared.

نصائح أخرى

I guess you don't have the INTERNET permission in your manifest?

The problem is that NBT name resolution works by sending UDP broadcast packets on the LAN, and the emulator lives on its own virtual LAN, connected to your host PC only by a virtual NAT router. Broadcast packets don't cross between different subnets, so nothing on your LAN sees the name query.

I have the same problem. The only ideas for solving it that I know are:

  • Set up a WINS server on your LAN, and point your app at it with the jcifs.netbios.wins property,

or,

  • Create an LMHOSTS file in the emulator's filesystem, containing the names and IPs of the hosts on your LAN that you want to be able to reach, and point your app at it with the jcifs.netbios.lmhosts property.

If it was possible to run something on the emulator that could serve as a NetBIOS Master Browser, there might be a third solution, but I haven't researched that enough yet.

The LMHOSTS solution isn't ideal, because you don't (AFAIK) get to browse for workgroups and hosts. That should work with a WINS server, but I haven't tried it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top