Class SocketClient.Builder<B extends SocketClient.Builder<B>>
- Type Parameters:
B
- the type of the Builder that is returned
- All Implemented Interfaces:
BuilderInterface
- Enclosing class:
SocketClient
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Finish building theSocketClient
object.onEvent
(SocketClient.EventCallback handler) Emitted whenclient
's activity onconnectable
changes state.setEnableProxy
(boolean enableProxy) Enable proxy support.setFamily
(SocketFamily family) The address family to use for socket construction.setLocalAddress
(SocketAddress localAddress) The local address constructed sockets will be bound to.setProtocol
(SocketProtocol protocol) The protocol to use for socket construction, or0
for default.setProxyResolver
(ProxyResolver proxyResolver) The proxy resolver to usesetTimeout
(int timeout) The I/O timeout for sockets, in seconds, or0
for none.setTls
(boolean tls) Whether to create TLS connections.setTlsValidationFlags
(Set<TlsCertificateFlags> tlsValidationFlags) Deprecated.setTlsValidationFlags
(TlsCertificateFlags... tlsValidationFlags) Deprecated.setType
(SocketType type) The type to use for socket construction.Methods inherited from class org.gnome.gobject.GObject.Builder
onNotify
Methods inherited from class io.github.jwharm.javagi.gobject.Builder
addBuilderProperty, connect, connect, connectSignals, getArena, getNames, getValues
-
Constructor Details
-
Builder
protected Builder()Default constructor for aBuilder
object.
-
-
Method Details
-
build
Finish building theSocketClient
object. This will callGObject.withProperties(org.gnome.glib.Type, java.lang.String[], org.gnome.gobject.Value[])
to create a new GObject instance, which is then cast toSocketClient
.- Overrides:
build
in classGObject.Builder<B extends SocketClient.Builder<B>>
- Returns:
- a new instance of
SocketClient
with the properties that were set in the Builder object.
-
setEnableProxy
Enable proxy support.- Parameters:
enableProxy
- the value for theenable-proxy
property- Returns:
- the
Builder
instance is returned, to allow method chaining
-
setFamily
The address family to use for socket construction.- Parameters:
family
- the value for thefamily
property- Returns:
- the
Builder
instance is returned, to allow method chaining
-
setLocalAddress
The local address constructed sockets will be bound to.- Parameters:
localAddress
- the value for thelocal-address
property- Returns:
- the
Builder
instance is returned, to allow method chaining
-
setProtocol
The protocol to use for socket construction, or0
for default.- Parameters:
protocol
- the value for theprotocol
property- Returns:
- the
Builder
instance is returned, to allow method chaining
-
setProxyResolver
The proxy resolver to use- Parameters:
proxyResolver
- the value for theproxy-resolver
property- Returns:
- the
Builder
instance is returned, to allow method chaining
-
setTimeout
The I/O timeout for sockets, in seconds, or0
for none.- Parameters:
timeout
- the value for thetimeout
property- Returns:
- the
Builder
instance is returned, to allow method chaining
-
setTls
Whether to create TLS connections.- Parameters:
tls
- the value for thetls
property- Returns:
- the
Builder
instance is returned, to allow method chaining
-
setTlsValidationFlags
Deprecated.The TLS validation flags used when creating TLS connections. The default value isTlsCertificateFlags.VALIDATE_ALL
.GLib guarantees that if certificate verification fails, at least one flag will be set, but it does not guarantee that all possible flags will be set. Accordingly, you may not safely decide to ignore any particular type of error. For example, it would be incorrect to mask
TlsCertificateFlags.EXPIRED
if you want to allow expired certificates, because this could potentially be the only error flag set even if other problems exist with the certificate. Therefore, there is no safe way to use this property. This is not a horrible problem, though, because you should not be attempting to ignore validation errors anyway. If you really must ignore TLS certificate errors, connect to theGSocketClient
::event signal, wait for it to be emitted withSocketClientEvent.TLS_HANDSHAKING
, and use that to connect toGTlsConnection
::accept-certificate.- Parameters:
tlsValidationFlags
- the value for thetls-validation-flags
property- Returns:
- the
Builder
instance is returned, to allow method chaining
-
setType
The type to use for socket construction.- Parameters:
type
- the value for thetype
property- Returns:
- the
Builder
instance is returned, to allow method chaining
-
setTlsValidationFlags
Deprecated.The TLS validation flags used when creating TLS connections. The default value isTlsCertificateFlags.VALIDATE_ALL
.GLib guarantees that if certificate verification fails, at least one flag will be set, but it does not guarantee that all possible flags will be set. Accordingly, you may not safely decide to ignore any particular type of error. For example, it would be incorrect to mask
TlsCertificateFlags.EXPIRED
if you want to allow expired certificates, because this could potentially be the only error flag set even if other problems exist with the certificate. Therefore, there is no safe way to use this property. This is not a horrible problem, though, because you should not be attempting to ignore validation errors anyway. If you really must ignore TLS certificate errors, connect to theGSocketClient
::event signal, wait for it to be emitted withSocketClientEvent.TLS_HANDSHAKING
, and use that to connect toGTlsConnection
::accept-certificate.- Parameters:
tlsValidationFlags
- the value for thetls-validation-flags
property- Returns:
- the
Builder
instance is returned, to allow method chaining
-
onEvent
Emitted whenclient
's activity onconnectable
changes state. Among other things, this can be used to provide progress information about a network connection in the UI. The meanings of the differentevent
values are as follows:SocketClientEvent.RESOLVING
:client
is about to look upconnectable
in DNS.connection
will benull
.
SocketClientEvent.RESOLVED
:client
has successfully resolvedconnectable
in DNS.connection
will benull
.
SocketClientEvent.CONNECTING
:client
is about to make a connection to a remote host; either a proxy server or the destination server itself.connection
is theGSocketConnection
, which is not yet connected. Since GLib 2.40, you can access the remote address via g_socket_connection_get_remote_address().
SocketClientEvent.CONNECTED
:client
has successfully connected to a remote host.connection
is the connectedGSocketConnection
.
SocketClientEvent.PROXY_NEGOTIATING
:client
is about to negotiate with a proxy to get it to connect toconnectable
.connection
is theGSocketConnection
to the proxy server.
SocketClientEvent.PROXY_NEGOTIATED
:client
has negotiated a connection toconnectable
through a proxy server.connection
is the stream returned from g_proxy_connect(), which may or may not be aGSocketConnection
.
SocketClientEvent.TLS_HANDSHAKING
:client
is about to begin a TLS handshake.connection
is aGTlsClientConnection
.
SocketClientEvent.TLS_HANDSHAKED
:client
has successfully completed the TLS handshake.connection
is aGTlsClientConnection
.
SocketClientEvent.COMPLETE
:client
has either successfully connected toconnectable
(in which caseconnection
is theGSocketConnection
that it will be returning to the caller) or has failed (in which caseconnection
isnull
and the client is about to return an error).
Each event except
SocketClientEvent.COMPLETE
may be emitted multiple times (or not at all) for a given connectable (in particular, ifclient
ends up attempting to connect to more than one address). However, ifclient
emits theGSocketClient
::event signal at all for a given connectable, then it will always emit it withSocketClientEvent.COMPLETE
when it is done.Note that there may be additional
GSocketClientEvent
values in the future; unrecognizedevent
values should be ignored.- Parameters:
handler
- the signal handler- Returns:
- the
Builder
instance is returned, to allow method chaining - See Also:
-