gpt4 book ai didi

java - 通过网络发送文件 - JAVA

转载 作者:行者123 更新时间:2023-12-01 10:35:10 24 4
gpt4 key购买 nike

我正在编写一个应用程序,该应用程序的所有者必须能够将文件发送到网络中的其他可用设备。此时我可以检索连接到网络的设备的所有 IP 地址。

如果我有这些设备的内部 IP 地址,是否可以将文件发送到这些设备

当前代码:

InetAddress localhost = null;
try {
localhost = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// this code assumes IPv4 is used
byte[] ip = localhost.getAddress();

for (int i = 1; i <= 254; i++)
{
ip[3] = (byte)i;
InetAddress address = null;
try {
address = InetAddress.getByAddress(ip);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

try {
if (address.isReachable(100))
{
System.out.println(address + " machine is turned on and can be pinged");
}
else if (!address.getHostAddress().equals(address.getHostName()))
{
System.out.println(address + " machine is known in a DNS lookup");
}
else
{
System.out.println(address + " the host address and host name are equal, meaning the host name could not be resolved");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

最佳答案

您必须在目标设备上有一些备用设备 - 一个将接收文件的应用程序。或者,您可以使用内置组件和硬件(例如蓝牙)共享文件。

关于java - 通过网络发送文件 - JAVA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34795678/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com