android - Wi-Fi P2P 从 Linux 到 Android

标签 android linux sockets wifip2p

我想以编程方式将文件从具有 Wi-Fi 访问权限、运行 Linux(客户端)的 Raspberry Pi 传输到 Android 手机(主机)。我正在使用 this link作为如何在 Android 上设置 P2P 连接的指南,但我找不到任何引用来处理非 Android 设备上的客户端。我知道我可以使用 this link提供有关将客户端连接到主机的文档,但我没有关于如何实际发送文件的线索。

从本质上讲,我想知道的是:从 Android 文档中,我可以在 Linux 上做些什么来获得与此相同的效果吗?我完全被误导了吗?

/**
 * Create a client socket with the host,
 * port, and timeout information.
 */
socket.bind(null);
socket.connect((new InetSocketAddress(host, port)), 500);

/**
 * Create a byte stream from a JPEG file and pipe it to the output stream
 * of the socket. This data is retrieved by the server device.
 */
OutputStream outputStream = socket.getOutputStream();
ContentResolver cr = context.getContentResolver();
InputStream inputStream = null;
inputStream = cr.openInputStream(Uri.parse("path/to/picture.jpg"));
while ((len = inputStream.read(buf)) != -1) {
    outputStream.write(buf, 0, len);
}
outputStream.close();
inputStream.close();

编辑:也许我困了,但如果设备已连接,有没有办法简单地对待它,类似于 this ? Android 文档声明它支持 UPnP 和 Bonjour 作为服务,如果这可以提供任何方向的话。如果是这样,在传输大型(最大 5Gb)文件时我应该注意什么?如果不相关,我道歉。

编辑 2:建立连接的解决方案在 wpa_cli特别是命令 p2p_find发现,p2p_peers看看发现了什么,p2p_connect <MAC_of_peer> pbc go_intent=0停止搜索并连接到 Android 主机。您可以看到它显示为带有 ip a 的本地网络。 .但是,现在我似乎在 Android 端遇到了问题,冒险继续 this question .

最佳答案

建立连接的解决方案在wpa_cli特别是命令 p2p_find发现,p2p_peers看看发现了什么,p2p_connect <MAC_of_peer> pbc go_intent=0停止搜索并连接到 Android 主机。您可以看到它显示为带有 ip a 的本地网络。 .但是,现在我似乎在 Android 端遇到了问题,冒险继续 this question , 对于任何有兴趣的人。

关于android - Wi-Fi P2P 从 Linux 到 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62187487/

相关文章:

android - 我在 .android 文件夹中找不到 adb_usb.ini 文件?

linux - ctrl+c 不杀死后台功能

Java -> C++ TCP 套接字直到关闭才发送

android - 如何在我的应用程序中使用 ScreenCap.cpp?

Android ExpandableListView获取bindChildView内的组号

android - 为什么我无法使用 Linkedin android sdk 登录?

c++ - 我的 Linux 应用程序端口在停止时被另一个服务占用

linux - 如何跟踪Linux内核中的write系统调用?

linux - 选择非阻塞读取

c++ - 服务器未在 C++ 套接字中接收到尾随 long