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
I guess you don't have the INTERNET permission in your manifest?
I was using the emulator. When I ran the app on real hardware the problem disappeared.
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.
精彩评论