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(Jid from,
String namespace,
Consumer<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.
|
void |
send(StreamElement element)
Sends an element.
|
String |
toString() |
getHostname, getPort, getProxy, getXmppSessionpublic final void connect(Jid from, String namespace, Consumer<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 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 ConnectionCopyright © 2014–2015 XMPP.rocks. All rights reserved.