JCIFS、Android 和 getbyname

发布于 2024-10-25 05:23:46 字数 265 浏览 12 评论 0原文

好吧,尝试了以下代码:

import jcifs.netbios.NbtAddress;
...

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

它抛出了该异常。 有什么想法吗?我已经在 LAN 上的几台指定机器上尝试过

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

等往事风中吹 2024-11-01 05:23:53

问题在于,NBT 名称解析通过在 LAN 上发送 UDP 广播数据包来工作,而模拟器位于其自己的虚拟 LAN 上,仅通过虚拟 NAT 路由器连接到主机 PC。广播数据包不会在不同子网之间交叉,因此 LAN 上的任何内容都看不到名称查询。

我有同样的问题。据我所知,解决这个问题的唯一想法是:

  • 在 LAN 上设置 WINS 服务器,并使用 jcifs.netbios.wins 属性将应用程序指向它,

或者

  • 在模拟器的文件系统,包含您希望能够访问的 LAN 上主机的名称和 IP,并使用 jcifs.netbios.lmhosts 属性将您的应用程序指向该文件系统。

如果可以在模拟器上运行一些可以用作 NetBIOS 主浏览器的东西,可能还有第三种解决方案,但我还没有对此进行足够的研究。

LMHOSTS 解决方案并不理想,因为您(据我所知)无法浏览工作组和主机。这应该适用于 WINS 服务器,但我还没有尝试过。

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.

假情假意假温柔 2024-11-01 05:23:51

我用的是模拟器。
当我在真实硬件上运行该应用程序时,问题就消失了。

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

随心而道 2024-11-01 05:23:50

我猜你的清单中没有互联网权限?

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文