添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft Edge More info about Internet Explorer and Microsoft Edge
public ref class HostName sealed : IStringable
/// [Windows.Foundation.Metadata.Activatable(Windows.Networking.IHostNameFactory, 65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class HostName final : IStringable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.Activatable(Windows.Networking.IHostNameFactory, 65536, "Windows.Foundation.UniversalApiContract")]
class HostName final : IStringable
[Windows.Foundation.Metadata.Activatable(typeof(Windows.Networking.IHostNameFactory), 65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class HostName : IStringable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.Activatable(typeof(Windows.Networking.IHostNameFactory), 65536, "Windows.Foundation.UniversalApiContract")]
public sealed class HostName : IStringable
function HostName(hostName)
Public NotInheritable Class HostName
Implements IStringable
Inheritance
Object Platform::Object IInspectable HostName

Remarks

The HostName class is used to initialize and provide data for a hostname used in network apps. A HostName object can be used for a local hostname or a remote hostname used to establish a network connection.

The HostName object is used by many classes in other related namespaces for network apps. These include the following:

  • Many classes in the Windows.Networking.Sockets namespace using sockets. Methods on the DatagramSocket and StreamSocket classes can be used to establish network connections and transfer data to a remote HostName object.
  • The NetworkInformation class in the Windows.Networking.Connectivity namespace. The following example creates a HostName and then tries to connect to the HostName using a StreamSocket .
  • using Windows.Networking;
    using Windows.Networking.Sockets;
    HostName serverHost = new HostName("www.contoso.com");
    StreamSocket clientSocket = new Windows.Networking.Sockets.StreamSocket();
    // Try to connect to the remote host
    await clientSocket.ConnectAsync(serverHost, "http");
    
    #include <winrt/Windows.Networking.Sockets.h>
    using namespace winrt;
    int main()
        winrt::init_apartment();
        Windows::Networking::HostName hostName{ L"www.contoso.com" };
        Windows::Networking::Sockets::StreamSocket streamSocket;
        // Try to connect.
        streamSocket.ConnectAsync(hostName, L"http").get();
    
    using namespace Windows::Networking;
    using namespace Windows::Networking::Sockets;
    HostName^ serverHost= ref new HostName("www.contoso.com");
    StreamSocket^ clientSocket = ref new StreamSocket();
    // Try to connect to the remote host
    clientSocket->ConnectAsync(serverHost, "http");