在商店App中创建套接字连接不工作

本文关键字:套接字 连接 工作 创建 App | 更新日期: 2023-09-27 18:17:17

我刚刚向Windows Phone Store发布了一款应用,经过彻底的调试,在调试和发布模式下测试的功能与我使用从商店下载的应用时的功能不一样。当从我的解决方案中测试调试和发布模式时,我没有问题(在设备或模拟器上),一切都很好。从商店下载后,我只返回SocketError.NetworkDown错误?

我正在创建一个Socket连接来收集网络接口信息。

private async void UpdateCurrentInterface()
    {
        Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        // To run this application you should specify the name of a server on your network that is running
        // the required service. 
        string serverName = "www.bing.com";
        // This identifies the port over which to communicate.
        int portNumber = 80;
        // Create DnsEndPoint. 
        DnsEndPoint hostEntry = new DnsEndPoint(serverName, portNumber);
        // Create a SocketAsyncEventArgs object to be used in the connection request.
        SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
        socketEventArg.RemoteEndPoint = hostEntry;
        socketEventArg.UserToken = socket;
        socketEventArg.Completed += ShowNetworkInterfaceInformation1;
        // // Make an asynchronous Connect request over the socket.
        socket.ConnectAsync(socketEventArg);
    }
    /// <summary>
    /// Display the network information using the GetCurrentNetworkInterface extension method on the socket.
    /// </summary>
    /// <remarks>This is the callback from the ConnectAsync method.</remarks>
    private void ShowNetworkInterfaceInformation1(object s, SocketAsyncEventArgs e)
    {
        // When ConnectAsync was called it was passed the socket object in
        // the UserToken field of the socketEventArg. This context is retrieved once
        // the ConnectAsync has completed.
        Socket socket = e.UserToken as Socket;
        // Only call GetCurrentNetworkInterface if the connection was successful.
        if (e.SocketError == SocketError.Success)
        {
            NetworkInterfaceInfo netInterfaceInfo = socket.GetCurrentNetworkInterface();
            // We are making UI updates, so make sure these happen on the UI thread.
            Dispatcher.BeginInvoke(() =>
            {
                currentTypeTextBlock.Text = GetInterfaceTypeString(netInterfaceInfo.InterfaceType);
                currentNameTextBlock.Text = name = netInterfaceInfo.InterfaceName;
                string change = "";
                if (netInterfaceInfo.InterfaceState.ToString() == "Connected")
                    currentStateTextBlock.Text = "connected";
                else
                    currentStateTextBlock.Text = "disconnected";
            });
        }
        else if (e.SocketError == SocketError.NetworkDown)
        {
            DisplayMessage("Could not connect.", "Network Down Error", MessageBoxButton.OK);
        }
        // Close our socket since we no longer need it.
        socket.Close();
    }

在商店App中创建套接字连接不工作

包括ID_CAP_NETWORKING作为WMAppManifest的能力