0

我正在尝试让 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 是否可用,如果可用则进行连接。

4

1 回答 1

2

我发现使用 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;
}
于 2011-05-02T15:52:29.573 回答