Resolver


Object Hierarchy:

Object hierarchy for Resolver

Description:

public abstract class Resolver : Object

Resolver provides cancellable synchronous and asynchronous DNS resolution, for hostnames ( lookup_by_address, lookup_by_name and their async variants) and SRV (service) records (lookup_service).

NetworkAddress and NetworkService provide wrappers around Resolver functionality that also implement SocketConnectable, making it easy to connect to a remote host/service.

Example: Resolver, lookup by name, sync:

public static int main () {
// Resolve hostname to IP address
try {
Resolver resolver = Resolver.get_default ();
List<InetAddress> addresses = resolver.lookup_by_name ("www.google.com", null);

// Example output:
// ``173.194.35.179``
// ``173.194.35.178``
// ``173.194.35.177``
// ``173.194.35.176``
// ``173.194.35.180``
// ``2a00:1450:4016:801::1013``
foreach (InetAddress address in addresses) {
print ("%s\n", address.to_string ());
}
} catch (Error e) {
print ("Error: %s\n", e.message);
}

return 0;
}

valac --pkg gio-2.0 GLib.Resolver.lookup_by_name.vala

Example: Resolver, lookup by name, async:

public static int main () {
MainLoop loop = new MainLoop ();

Resolver resolver = Resolver.get_default ();
resolver.lookup_by_name_async.begin ("www.google.com", null, (obj, res) => {
try {
// Example output:
// ``173.194.35.179``
// ``173.194.35.178``
// ``173.194.35.177``
// ``173.194.35.176``
// ``173.194.35.180``
// ``2a00:1450:4016:801::1013``
List<InetAddress> addresses = resolver.lookup_by_name_async.end (res);
foreach (InetAddress address in addresses) {
print ("%s\n", address.to_string ());
}
} catch (Error e) {
print ("Error: %s\n", e.message);
}

loop.quit ();
});

// Block until loop.quit is called:
loop.run ();
return 0;
}

valac --pkg gio-2.0 GLib.Resolver.lookup_by_name_async.vala


Namespace: GLib
Package: gio-2.0

Content:

Static methods:

Creation methods:

Methods:

Signals:

Inherited Members: