public final class TcpConnection extends Connection
If no hostname is set (null or empty) the connection tries to resolve the hostname via an SRV DNS lookup.
This class is unconditionally thread-safe.
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the TCP connection.
|
void |
connect(rocks.xmpp.addr.Jid from,
String namespace,
Consumer<rocks.xmpp.addr.Jid> onStreamOpened)
Connects to the specified XMPP server using a socket connection.
|
String |
getStreamId()
Gets the stream id of this connection.
|
boolean |
isSecure()
Indicates whether this connection is secured by TLS/SSL.
|
boolean |
isUsingAcknowledgements()
Indicates, whether this connection is using acknowledgements.
|
CompletableFuture<Void> |
send(StreamElement element)
Sends an element over this connection.
|
String |
toString() |
getConfiguration, getHostname, getPort, getProxypublic final void connect(rocks.xmpp.addr.Jid from,
String namespace,
Consumer<rocks.xmpp.addr.Jid> onStreamOpened)
throws IOException
XmppClient.login(String, String) method.
If only a XMPP service domain has been specified, it is tried to resolve the FQDN via SRV lookup.
If that fails, it is tried to connect directly the XMPP service domain on port 5222.
If a hostname and port have been specified, these are used to establish the connection.
If a proxy has been specified, the connection is established through this proxy.
connect in class Connectionfrom - The optional 'from' attribute in the stream header.namespace - The content namespace, e.g. "jabber:client".onStreamOpened - The callback which gets notified when the stream gets opened, i.e. when the server has responded with a stream header. The parameter of the consumer is the stream id.IOException - If the underlying socket throws an exception.public boolean isSecure()
ConnectionisSecure in class Connectionpublic final CompletableFuture<Void> send(StreamElement element)
Connectionsend in class Connectionelement - The element.public final void close()
throws Exception
</stream:stream>, then shuts down the writer so that no more stanzas can be sent.
After that it shuts down the reader and awaits shortly for any stanzas from the server and the server gracefully closing the stream with </stream:stream>.
Eventually the socket is closed.IOException - If the socket throws an I/O exception.Exceptionpublic final String getStreamId()
ConnectiongetStreamId in class Connectionpublic final boolean isUsingAcknowledgements()
ConnectionTCP and WebSocket connections use XEP-0198: Stream Management to acknowledge stanzas.
BOSH connections use another mechanism for acknowledgements, described in XEP-0124 § 9. Acknowledgements.
isUsingAcknowledgements in class ConnectionCopyright © 2014–2017 XMPP.rocks. All rights reserved.