Share via


HostName Class

Definition

Provides data for a hostname or an IP address.

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
Attributes
Implements

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)
App capabilities
internetClient privateNetworkClientServer

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:

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");

Constructors

HostName(String)

Creates a new HostName object from a string that contains a hostname or an IP address.

Properties

CanonicalName

Gets the canonical name for the HostName object.

DisplayName

Gets the display name for the HostName object.

IPInformation

Gets the IPInformation object for a local IP address assigned to a HostName object.

RawName

Gets the original string used to construct the HostName object.

Type

Gets the HostNameType of the HostName object.

Methods

Compare(String, String)

Compares two strings to determine if they represent the same hostname.

IsEqual(HostName)

Determines whether the specified HostName object has an equivalent value to the current HostName object.

ToString()

Returns a string that represents the HostName object.

Applies to

See also