Class NetworkAddress
- All Implemented Interfaces:
SocketConnectable,Proxy
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 SocketConnectable for an example of using the connectable
interface.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classNetworkAddress.Builder<B extends NetworkAddress.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static classNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClassNested classes/interfaces inherited from interface org.gnome.gio.SocketConnectable
SocketConnectable.SocketConnectable$Impl, SocketConnectable.SocketConnectableIface -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new NetworkAddress.NetworkAddress(MemorySegment address) Create a NetworkAddress proxy instance for the provided memory address.NetworkAddress(String hostname, short port) Creates a newGSocketConnectablefor connecting to the givenhostnameandport. -
Method Summary
Modifier and TypeMethodDescriptionprotected NetworkAddressasParent()Returns this instance as if it were its parent type.static NetworkAddress.Builder<? extends NetworkAddress.Builder> builder()ANetworkAddress.Builderobject constructs aNetworkAddresswith the specified properties.Getsaddr'shostname.static MemoryLayoutThe memory layout of the native struct.shortgetPort()Getsaddr'sport number@Nullable StringGetsaddr'sschemestatic @Nullable TypegetType()Get the GType of the NetworkAddress classstatic NetworkAddressloopback(short port) Creates a newGSocketConnectablefor connecting to the local host over a loopback connection to the givenport.This is intended for use in connecting to local services which may be running on IPv4 or IPv6.static NetworkAddressCreates a newGSocketConnectablefor connecting to the givenhostnameandport.May fail and returnnullin case parsinghostAndPortfails.static NetworkAddressCreates a newGSocketConnectablefor connecting to the givenuri.May fail and returnnullin case parsingurifails.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCodeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.gnome.gio.SocketConnectable
enumerate, formatAsString, proxyEnumerate
-
Constructor Details
-
NetworkAddress
Create a NetworkAddress proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
NetworkAddress
Creates a newGSocketConnectablefor connecting to the givenhostnameandport.Note that depending on the configuration of the machine, a
hostnameoflocalhostmay refer to the IPv4 loopback address only, or to both IPv4 and IPv6; use g_network_address_new_loopback() to create aGNetworkAddressthat is guaranteed to resolve to both addresses.- Parameters:
hostname- the hostnameport- the port- Since:
- 2.22
-
NetworkAddress
public NetworkAddress()Creates a new NetworkAddress.
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName(). This will call the native function pointer of this virtual method in the typeclass of the parent type. -
loopback
Creates a newGSocketConnectablefor connecting to the local host over a loopback connection to the givenport.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, g_network_address_new() will often only return an IPv4 address when resolvinglocalhost, and an IPv6 address forlocalhost6.g_network_address_get_hostname() will always return
localhostfor aGNetworkAddresscreated with this constructor.- Parameters:
port- the port- Returns:
- the new
GNetworkAddress - Since:
- 2.44
-
parse
Creates a newGSocketConnectablefor connecting to the givenhostnameandport.May fail and returnnullin case parsinghostAndPortfails.hostAndPortmay 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
hostAndPortthendefaultPortwill be used as the port number to connect to.In general,
hostAndPortis expected to be provided by the user (allowing them to give the hostname, and a port override if necessary) anddefaultPortis expected to be provided by the application.(The port component of
hostAndPortcan 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.)- Parameters:
hostAndPort- the hostname and optionally a portdefaultPort- the default port if not inhostAndPort- Returns:
- the new
GNetworkAddress, ornullon error - Throws:
GErrorException- seeGError- Since:
- 2.22
-
parseUri
Creates a newGSocketConnectablefor connecting to the givenuri.May fail and returnnullin case parsingurifails.Using this rather than g_network_address_new() or g_network_address_parse() allows
GSocketClientto determine when to use application-specific proxy protocols.- Parameters:
uri- the hostname and optionally a portdefaultPort- The default port if none is found in the URI- Returns:
- the new
GNetworkAddress, ornullon error - Throws:
GErrorException- seeGError- Since:
- 2.26
-
getHostname
Getsaddr'shostname. This might be either UTF-8 or ASCII-encoded, depending on what this NetworkAddress was created with.- Returns:
addr'shostname- Since:
- 2.22
-
getPort
public short getPort()Getsaddr'sport number- Returns:
addr'sport (which may be 0)- Since:
- 2.22
-
getScheme
Getsaddr'sscheme- Returns:
addr'sscheme (nullif not built from URI)- Since:
- 2.26
-
builder
ANetworkAddress.Builderobject constructs aNetworkAddresswith the specified properties. Use the variousset...()methods to set properties, and finish construction withNetworkAddress.Builder.build().- Returns:
- the builder object
-