【问题标题】:Re-connect to a specific AccessPoint using OpenNETCF使用 OpenNETCF 重新连接到特定接入点
【发布时间】:2011-08-13 02:11:42
【问题描述】:

我正在尝试让 Windows Mobile CE 的应用程序重新连接到启用 WEP 的特定网络(如果该网络可用)。我相信这段代码会扫描当前可用的接入点以获取对我需要的网络的引用:

                // we have communicated with the server, so save the access point for future reference
                INetworkInterface[] wniNet = NetworkInterface.GetAllNetworkInterfaces();
                foreach (NetworkInterface wni in wniNet)
                {
                    if (wni is WirelessNetworkInterface)
                    {
                        WirelessNetworkInterface wWireless = wni as WirelessNetworkInterface;
                        //if (mwniServerConnection == null)
                        if (string.IsNullOrEmpty(msAccessPointName))
                        {
                            MessageBox.Show("assigning: " + wWireless.AssociatedAccessPoint.ToString() + " to instance var.", "testing");

                            // first attempt to save the WEP enabled access point to the preferred networks
                            //WirelessZeroConfigNetworkInterface wWifiConnection = new WirelessZeroConfigNetworkInterface();
                            //wWifiConnection.AddPreferredNetwork(wWireless.AssociatedAccessPoint.ToString(),
                            //    wWireless.InfrastructureMode,
                            //    "9876543210",
                            //    1,
                            //    wWireless.AuthenticationMode,
                            //    WEPStatus.WEPEnabled,
                            //    null);
                            mwniServerConnection = wWireless;
                            msAccessPointName = wWireless.AssociatedAccessPoint.ToString();
                        }
                    }
                }

昨天找到了OpenNETCF库,我有点不知所措,我想问一下是否有任何代码示例可以测试网络ac是否可用,如果可用则连接。

【问题讨论】:

    标签: c# windows windows-mobile wifi opennetcf


    【解决方案1】:

    我发现使用 adapter.SetWirelessSettings 将手持设备重新连接到找到的特定接入点,以便在我的服务器运行的特定网络上进行通信:

    public static bool AttemptToReConnectAccessPoint()
    {
        bool wbRtn = false;
    
        // attempt to connect to the proper network
        if (U.mapAccessPoint != null)
        {
            // if we are currently on the right access point, we don't want to blow off the connection
            if (CheckIfAccessPointIsCurrent()) return true;
            foreach (OpenNETCF.Net.Adapter wAdapter in OpenNETCF.Net.Networking.GetAdapters())
            {
                bool wbFound = false;
                foreach (OpenNETCF.Net.AccessPoint wAccessPoint in wAdapter.NearbyAccessPoints)
                {
                    if (wAccessPoint.Name == U.mapAccessPoint.Name)
                    {
                        wbRtn = wAdapter.SetWirelessSettings(wAccessPoint.Name);
                        // give the re-connect script a second to finish
                        Thread.Sleep(1000);
                        Application.DoEvents();
                        break;
                    }
                }
                if (wbFound) break;
            }
        }
    
        return wbRtn;
    }
    

    【讨论】:

    • 感谢代码,当我测试它时,我必须添加 wbRtn = wAdapter.SetWirelessSettings(wAccessPoint.Name); wAdapter.RebindAdapter()
    • 谢谢,我实际上已经因为其他原因暂时搁置了这个版本的代码,但我会确保在回来时添加它。
    猜你喜欢
    • 2014-05-12
    • 2017-04-13
    • 2015-08-31
    • 2013-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-21
    相关资源
    最近更新 更多