0

特定の WEP 対応ネットワークが利用可能になった場合に、そのネットワークに Windows Mobile CE 用のアプリケーションを再接続しようとしています。このコードは、現在利用可能なアクセス ポイントをスキャンして、必要なネットワークへの参照を取得していると思います。

                // 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 に答える