Ubuntu - 在 Ad Hoc 网络中使用套接字连接到 PC 时出现 UnknownHostException
我创建了一个 FileSystemListener
来侦听文件夹中的文件并将它们发送到指定的 IP 地址。这一切都已使用标准无线网络进行了测试,但在临时网络上运行时出现unkownhostexception。
我不确定这是否是我应该在超级用户或这里询问的问题,因为我不确定这是否是我的代码或 Ubuntu 的问题。
我可以 ping 无线网络上的另一台 PC,但通过 java 连接时不断出现上述异常。
不确定它是否有帮助,但这是我能想到的最基本的 SSCE:
import java.net.Socket;
public class ClientTester {
public static void main(String[] args) {
Socket s = new Socket("192.168.0.1", 4440);
}
}
之前有人遇到过这个问题,想看看在我交叉发布到超级用户之前这是否是一个 Java 问题。
谢谢!
I have created a FileSystemListener
that listens for files in a folder and sends them to a specified IP address. This has all been tested with a standard wireless network but I am getting an unkownhostexception when running it on an ad hoc network.
I was not sure if this was something I should ask on Superuser, or here, as I am not sure if it is an issue with my code or Ubuntu.
I can ping the other PC on the wireless network but I keep getting the above exception when connecting through java.
Not sure if it helps but here is the most basic SSCE I can think of:
import java.net.Socket;
public class ClientTester {
public static void main(String[] args) {
Socket s = new Socket("192.168.0.1", 4440);
}
}
Anyone come across this before, wanted to see if it was a Java issue before I cross posted in Superuser.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了正确编译,
UnknownHostException
“必须被捕获或声明为抛出”。例如:
}
To compile correctly,
UnknownHostException
"must be caught or declared to be thrown."For example:
}
如果这适用于常规基础架构模式,但不适用于临时模式,则您可能没有正确配置临时模式。您能向我们展示您的 /etc/network/interfaces 配置吗?
If this works with regular infrastructure mode, but not with ad-hoc mode you probably haven't configured the ad-hoc mode properly. Could you show us your /etc/network/interfaces config?