SocketAddressEnumerator


Object Hierarchy:

GLib.SocketAddressEnumerator GLib.SocketAddressEnumerator GLib.SocketAddressEnumerator GLib.Object GLib.Object GLib.Object->GLib.SocketAddressEnumerator

Description:

[ CCode ( type_id = "g_socket_address_enumerator_get_type ()" ) ]
public abstract class SocketAddressEnumerator : Object

SocketAddressEnumerator is an enumerator type for SocketAddress instances.

It is returned by enumeration functions such as enumerate, which returns a SocketAddressEnumerator to list each SocketAddress which could be used to connect to that SocketConnectable.

Enumeration is typically a blocking operation, so the asynchronous methods next_async and next_async.end should be used where possible.

Each SocketAddressEnumerator can only be enumerated once. Once next has returned null, further enumeration with that SocketAddressEnumerator is not possible, and it can be unreffed.

Example: SocketAddressEnumerator:

public static void example_sync () {
InetAddress address = new InetAddress.from_string ("208.80.152.201");
InetSocketAddress socket_address = new InetSocketAddress (address, 80);

try {
SocketAddressEnumerator en = socket_address.enumerate ();
for (SocketAddress add = en.next (); add != null; add = en.next ()) {
print ("%s\n", add.get_family ().to_string ());
}
} catch (Error e) {
print ("Error: %s\n", e.message);
}
}

public async void example_async () {
InetAddress address = new InetAddress.from_string ("208.80.152.201");
InetSocketAddress socket_address = new InetSocketAddress (address, 80);

try {
SocketAddressEnumerator en = socket_address.enumerate ();
for (SocketAddress add = yield en.next_async (); add != null; add = yield en.next_async ()) {
print ("%s\n", add.get_family ().to_string ());
}
} catch (Error e) {
print ("Error: %s\n", e.message);
}
}

public static int main (string[] args) {
// Output: ``G_SOCKET_FAMILY_IPV4`` (15. Nov. 2012)
example_sync ();

// Output: ``G_SOCKET_FAMILY_IPV4`` (15. Nov. 2012)
MainLoop loop = new MainLoop ();
example_async.begin ((obj, res) => {
loop.quit ();
});
loop.run ();
return 0;
}

valac --pkg gio-2.0 GLib.SocketAddressEnumerator.vala
All known sub-classes:

Namespace: GLib
Package: gio-2.0

Content:

Creation methods:

Methods:

Inherited Members:

All known members inherited from class GLib.Object



2022 vala-language.org