HostName Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
- 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:
- 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");
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. |