Mac/Windows 和 Android 之间的 WiFi-Direct 通信

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11722891/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 08:36:04  来源:igfitidea点击:

WiFi-Direct communication between Mac/Windows and Android

androidwindowsmacoswifiwifi-direct

提问by Elias Atahi

Is it possible to let an Android (>4.0) device establish a WiFi-Direct connection with a Mac OS or Windows device?

是否可以让 Android (>4.0) 设备与 Mac OS 或 Windows 设备建立 WiFi-Direct 连接?

回答by slayton

According to the Wifi-Direct Docsthe protocol allows:

根据Wifi-Direct Docs,该协议允许:

Android 4.0 (API level 14) or later devices with the appropriate hardware to connect directly to each other via Wi-Fi

Android 4.0(API 级别 14)或更高版本的设备,具有适当的硬件以通过 Wi-Fi 直接相互连接

It doesn't look like Google provides this functionality via the API. Although WiFi-Direct isn't a proprietary protocol and could be implemented for any platform. There are a few posts around the web of people trying to get Wifi-Direct to work under windows:

Google 似乎没有通过 API 提供此功能。尽管 WiFi-Direct 不是专有协议,可以为任何平台实现。网上有一些帖子试图让 Wifi-Direct 在 Windows 下工作:

回答by Pihhan

All you need is to use java.net.Socket. Depends on what do you mean by establish direct connection. TCP connection is established when on destination device (windows or mac) you open listening socket by ServerSocket. On other device you can use Socket with destination address. Of course, windows or mac box will propably have to open that port in firewall.

您只需要使用 java.net.Socket。取决于建立直接连接是什么意思。当您在目标设备(windows 或 mac)上通过 ServerSocket 打开侦听套接字时建立 TCP 连接。在其他设备上,您可以使用带有目标地址的 Socket。当然,windows 或 mac box 可能必须在防火墙中打开该端口。

I guess what you actually need to know is how to get name of target computer or how to discover computers on local network. Unfortunately, it does not depend on android version I think. You should check http://en.wikipedia.org/wiki/Zero_configuration_networkingabout some hints. I fear there might be problem in need to open privileged port on android, as normally you have to be root for that. And that would require rooted android.

我想您真正需要知道的是如何获取目标计算机的名称或如何发现本地网络上的计算机。不幸的是,我认为它不依赖于 android 版本。您应该查看http://en.wikipedia.org/wiki/Zero_configuration_networking 以了解一些提示。我担心在 android 上打开特权端口可能会出现问题,因为通常你必须是 root。这将需要有根的 android。

Of course you should specify what do you intend with that direct connection and what software do you need. If both ends have your application, you can just open any not allocated and unpriviledged port on android. Use UDP to broadcast periodically name of android device (propably ask user to enter name of his device). Use multicast to send requests, and receive replies the same way. Multicast sending and receiving would require your application on android and on windows and on mac also. Now you can read from multicast application what type of machine it is, and what local port it left open for your direct connection. From source of udp message you know where to connect.

当然,您应该指定您打算使用该直接连接做什么以及您需要什么软件。如果两端都有你的应用程序,你可以在android上打开任何未分配和非特权的端口。使用 UDP 定期广播 android 设备的名称(建议用户输入他的设备名称)。使用多播发送请求,并以相同的方式接收回复。多播发送和接收也需要您在 android、windows 和 mac 上的应用程序。现在您可以从多播应用程序读取它是什么类型的机器,以及它为您的直接连接打开的本地端口。从 udp 消息的来源,您知道连接的位置。

You may use some framework to speed things up. All this require some knowledge about networking, but I don't know simpler and well working solution. Unless you provide details about what is your direct connection to do.

您可以使用一些框架来加快速度。所有这些都需要一些有关网络的知识,但我不知道更简单且有效的解决方案。除非您提供有关您的直接联系要做什么的详细信息。