Gio.NetworkAddress

g GObject.GInterface GObject.GInterface Gio.SocketConnectable Gio.SocketConnectable GObject.GInterface->Gio.SocketConnectable GObject.Object GObject.Object Gio.NetworkAddress Gio.NetworkAddress GObject.Object->Gio.NetworkAddress Gio.SocketConnectable->Gio.NetworkAddress

Subclasses:

None

Methods

Inherited:

GObject.Object (37), Gio.SocketConnectable (3)

Structs:

GObject.ObjectClass (5)

class

new (hostname, port)

class

new_loopback (port)

class

parse (host_and_port, default_port)

class

parse_uri (uri, default_port)

get_hostname ()

get_port ()

get_scheme ()

Virtual Methods

Inherited:

GObject.Object (7), Gio.SocketConnectable (3)

Properties

Name

Type

Flags

Short Description

hostname

str

r/w/co

port

int

r/w/co

scheme

str

r/w/co

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

parent_instance

GObject.Object

r

Class Details

class Gio.NetworkAddress(**kwargs)
Bases:

GObject.Object, Gio.SocketConnectable

Abstract:

No

Structure:

Gio.NetworkAddressClass

GNetworkAddress provides an easy way to resolve a hostname and then attempt to connect to that host, handling the possibility of multiple IP addresses and multiple address families.

The enumeration results of resolved addresses *may* be cached as long as this object is kept alive which may have unexpected results if alive for too long.

See [iface`Gio`.SocketConnectable] for an example of using the connectable interface.

classmethod new(hostname, port)[source]
Parameters:
  • hostname (str) – the hostname

  • port (int) – the port

Returns:

the new Gio.NetworkAddress

Return type:

Gio.NetworkAddress

Creates a new Gio.SocketConnectable for connecting to the given hostname and port.

Note that depending on the configuration of the machine, a hostname of localhost may refer to the IPv4 loopback address only, or to both IPv4 and IPv6; use Gio.NetworkAddress.new_loopback() to create a Gio.NetworkAddress that is guaranteed to resolve to both addresses.

New in version 2.22.

classmethod new_loopback(port)[source]
Parameters:

port (int) – the port

Returns:

the new Gio.NetworkAddress

Return type:

Gio.NetworkAddress

Creates a new Gio.SocketConnectable for connecting to the local host over a loopback connection to the given port. This is intended for use in connecting to local services which may be running on IPv4 or IPv6.

The connectable will return IPv4 and IPv6 loopback addresses, regardless of how the host resolves localhost. By contrast, Gio.NetworkAddress.new() will often only return an IPv4 address when resolving localhost, and an IPv6 address for localhost6.

Gio.NetworkAddress.get_hostname() will always return localhost for a Gio.NetworkAddress created with this constructor.

New in version 2.44.

classmethod parse(host_and_port, default_port)[source]
Parameters:
  • host_and_port (str) – the hostname and optionally a port

  • default_port (int) – the default port if not in host_and_port

Raises:

GLib.Error

Returns:

the new Gio.NetworkAddress, or None on error

Return type:

Gio.NetworkAddress

Creates a new Gio.SocketConnectable for connecting to the given hostname and port. May fail and return None in case parsing host_and_port fails.

host_and_port may be in any of a number of recognised formats; an IPv6 address, an IPv4 address, or a domain name (in which case a DNS lookup is performed). Quoting with [] is supported for all address types. A port override may be specified in the usual way with a colon.

If no port is specified in host_and_port then default_port will be used as the port number to connect to.

In general, host_and_port is expected to be provided by the user (allowing them to give the hostname, and a port override if necessary) and default_port is expected to be provided by the application.

(The port component of host_and_port can also be specified as a service name rather than as a numeric port, but this functionality is deprecated, because it depends on the contents of /etc/services, which is generally quite sparse on platforms other than Linux.)

New in version 2.22.

classmethod parse_uri(uri, default_port)[source]
Parameters:
  • uri (str) – the hostname and optionally a port

  • default_port (int) – The default port if none is found in the URI

Raises:

GLib.Error

Returns:

the new Gio.NetworkAddress, or None on error

Return type:

Gio.NetworkAddress

Creates a new Gio.SocketConnectable for connecting to the given uri. May fail and return None in case parsing uri fails.

Using this rather than Gio.NetworkAddress.new() or Gio.NetworkAddress.parse() allows Gio.SocketClient to determine when to use application-specific proxy protocols.

New in version 2.26.

get_hostname()[source]
Returns:

self's hostname

Return type:

str

Gets self's hostname. This might be either UTF-8 or ASCII-encoded, depending on what self was created with.

New in version 2.22.

get_port()[source]
Returns:

self's port (which may be 0)

Return type:

int

Gets self's port number

New in version 2.22.

get_scheme()[source]
Returns:

self's scheme (None if not built from URI)

Return type:

str or None

Gets self's scheme

New in version 2.26.

Property Details

Gio.NetworkAddress.props.hostname
Name:

hostname

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

Hostname to resolve.

New in version 2.22.

Gio.NetworkAddress.props.port
Name:

port

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

Network port.

New in version 2.22.

Gio.NetworkAddress.props.scheme
Name:

scheme

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

URI scheme.

New in version 2.22.