lookup_by_name_async


Description:

[ Version ( since = "2.22" ) ]
public virtual async List<InetAddress> lookup_by_name_async (string hostname, Cancellable? cancellable = null) throws Error

Begins asynchronously resolving hostname to determine its associated IP address(es), and eventually calls callback , which must call lookup_by_name_async.end to get the result.

See lookup_by_name for more details.

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

Parameters:

this

a Resolver

hostname

the hostname to look up the address of

cancellable

a Cancellable, or null

callback

callback to call after resolution completes

user_data

data for callback




2022 vala-language.org