在 Windows 上使用 WiFi Direct Api? [英] On using the WiFi Direct Api on Windows?

查看:45
本文介绍了在 Windows 上使用 WiFi Direct Api?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个应用程序,我需要在桌面应用程序(在 Windows 10 上)和平板电脑(Android,但无关紧要)之间创建链接(阅读:WiFi 链接).工作流程:按钮 -> 根据需要提升权限 -> 创建托管网络类 WiFi 网络 -> 允许设备连接提供SSID/密码/动态 IP 地址...

I'm currently developing an application where I need to create a link (read: WiFi link) between a desktop app (on Windows 10) and a tablet (Android, but it is irrelevant). Workflow: Push button -> elevate privileges if required -> Create hosted network-like WiFi network -> Allow device to connect providing a SSID/password/dynamic IP address...

以前,我使用系统调用 netsh(以提升的权限运行应用程序)来创建托管网络.现在似乎越来越不可能以这种方式进行(例如:在同一台计算机上,它在 Win 7 上工作,但在 Win 10 上不再工作).这似乎是一个驱动程序问题,因为它仍然适用于外部 USB 天线,但不适用于内部天线.无论如何,我不想用这个解决方案走得更远.

Previously, I used a system call to netsh (running the app with elevated privileges) to create a hosted network. Now it seems it is less and less possible to proceed this way (example: on the same computer, it worked on Win 7 but it no longer works on Win 10). It seems to be a driver problem because it still works with an external USB antenna but not with the internal antenna. Any way, I don't want to go further with this solution.

我的目标:能够使用 API 以编程方式执行此操作.我看到很多关于WiFi Direct vs 托管网络的讨论,而且托管网络似乎是一种正在消失的技术而 WiFi Direct 前途光明???我不知道.

My goal: to be able to do this programmatically using an API. I saw a lot of discussions about WiFi Direct vs Hosted Network and it seems that Hosted Network is a vanishing technology while WiFi Direct has a brilliant future??? I don't know.

我发现了 WiFi Direct API,但它们看起来面向 Universal Windows (UWP) 而我希望能够以简单的方式使用它们C# 应用程序.这篇文章展示了如何破解系统并通过简单的 C# 控制台应用程序使用 API.到目前为止,一切都很好,它奏效了.

I found WiFi Direct API but they look Universal Windows (UWP) oriented while I want to be able to use them in a simple C# app. This post shows how to hack the system and use the API with a simple C# console app. So far, so good, it worked.

为了简单易用,我在Legacy 模式下使用了 API,以我的平板电脑看到网络的方式提供 SSID 和密码.WiFiDirectAdvertisementPublisherAdvertisement.LegacySettings.IsEnabled = true; 连接速度非常快,一切都很好.

In order to have a simple use, I used the API in Legacy mode, giving a SSID and a password in such a way my tablet see a network. WiFiDirectAdvertisementPublisherAdvertisement.LegacySettings.IsEnabled = true; The connection is very fast and everything is good.

它失败的地方是我使用了一个流媒体(类似飞溅的东西)并且它在 1-2 分钟后断开连接(流媒体断开连接,而不是 WiFi).相反,如果我只是转到 Windows 设置中的无线接入点"表单并激活它,则通信会保持超过 24 小时(并且现在仍在运行,没有任何缺陷).因此,问题不在于流光,也不在于 WiFi 设备硬件/驱动程序.我的第一个想法是有一个 WiFi Direct 设置,它设置得很糟糕,无法维持流式数据流.

Where it fails is that I use a streamer (something like splashtop) and it disconnects after 1-2 minutes (the streamer disconnects, not the WiFi). On the opposite, if I simply go to the "Wireless Access Point" form in Windows settings and activate it, the communication holds for more than 24 hours (and it's still running now without flaw). So, the problem is not with the streamer, neither the WiFi device hardware/driver. My first idea is that there is a WiFi Direct setting that is badly set to sustain a streaming data flow.

随之而来的是我无法在网上找到文档.Microsoft Wlanapi.dll 文档a> 马马虎虎......我仍然不知道我是否必须专注于WiFi Direct(真的?)还是坚持使用托管网络,因为它证明了这一点工作正常吗?

Going with that I'm unable to find doc on the web. The Microsoft Wlanapi.dll documentation is so-so... and I still don't know if I must focus to WiFi Direct (really?) or stick to Hosted Network because it proved it works fine?

这是我的代码,它可以很好地维护 WiFi 链接,但会使流媒体很快断开连接:

Here is my code that works fine to maintain a WiFi link but that makes the streamer to disconnect shortly:

using System;
using Windows.Devices.WiFiDirect;
using Windows.Security.Credentials;

namespace WFDcs_1
{
    class Program
    {
        private WiFiDirectAdvertisementPublisher mPublisher = null;
        private bool mConnected = false;

        static void Main(string[] args)
        {
            Program zeProgram = new Program(args);
        }

        Program(string[] args)
        {
            StartAdvertisement(WiFiDirectAdvertisementListenStateDiscoverability.Normal);

            Console.WriteLine("Hit a key to quit...");
            Console.ReadKey();
        }

        void StopAdvertisement()
        {
            if (mConnected)
            {
                mPublisher.Stop();
                mPublisher.StatusChanged -= OnStatusChanged;
            }
        }

        void StartAdvertisement(WiFiDirectAdvertisementListenStateDiscoverability discoverability)
        {
            if ( mPublisher == null )
            {
                mPublisher = new WiFiDirectAdvertisementPublisher();
            }

            mPublisher.StatusChanged += OnStatusChanged;
            mPublisher.Advertisement.IsAutonomousGroupOwnerEnabled = true;
            mPublisher.Advertisement.LegacySettings.IsEnabled = true;
            mPublisher.Advertisement.LegacySettings.Ssid = "MyGloriousSSID";

            PasswordCredential lCred = new PasswordCredential();
            lCred.Password = "test1234";

            mPublisher.Advertisement.LegacySettings.Passphrase = lCred;

            mPublisher.Advertisement.ListenStateDiscoverability = discoverability;
            mPublisher.Start();
        }

        void OnStatusChanged(WiFiDirectAdvertisementPublisher sender, WiFiDirectAdvertisementPublisherStatusChangedEventArgs statusEventArgs)
        {
            // *** 1 ***
            Console.WriteLine("OnStatusChanged(...): New connection status: {0}", statusEventArgs.Status.ToString());
        }
    }
}

我希望能参考一些教程、示例、提示,以及任何对我有帮助的内容.谢谢!

I would appreciate some reference to tutorials, examples, hints, whatever that could help me. Thank you!

推荐答案

在查看 Mike Petrichenko 引用的示例后,我最终找到了这个链接:(要下载的原生 C++ 示例),位于 此页面.它在传统模式下使用 WiFiDirect 来模拟托管网络.它使用 WRL.没有要破解的 *.vcxproj 文件,没有要链接到的奇怪"库.还有一些或多或少有用的解释这里.正是我想要的.

After looking to example refered to by Mike Petrichenko, I finaly found this link: (native c++ example to download) in this page. It makes use of WiFiDirect in legacy mode to simulate a hosted network. It uses WRL. No *.vcxproj file to hack, no "strange" library to link to. Also there are some more or less useful explanations here. Exactly what I wanted.

我必须说这个信息不容易找到...

I must say that this information was not easy to find...

这篇关于在 Windows 上使用 WiFi Direct Api?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆