public final class SocketConnection extends AbstractConnection implements TcpBinding
The default TCP socket connection as described in TCP Binding.
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.
Constructor and Description |
---|
SocketConnection(java.net.Socket socket,
XmppSession xmppSession,
TcpConnectionConfiguration configuration) |
Modifier and Type | Method and Description |
---|---|
java.util.concurrent.CompletionStage<java.lang.Void> |
closeFuture()
Returns a future which is complete, when the connection is closed.
|
void |
compressConnection(java.lang.String method,
java.lang.Runnable onSuccess)
Compresses the connection.
|
void |
flush()
Flushes the connection.
|
java.net.InetSocketAddress |
getRemoteAddress()
Gets the remote address of this connection.
|
boolean |
isSecure()
Indicates whether this connection is secured by TLS/SSL.
|
boolean |
isUsingAcknowledgements()
Indicates whether this connection uses acknowledgements, e.g. by means of stream management or BOSH acks.
|
java.util.concurrent.CompletionStage<java.lang.Void> |
open(SessionOpen sessionOpen)
Opens the XML stream to the peer entity.
|
void |
secureConnection()
This method is called from the reader thread.
|
java.util.concurrent.CompletableFuture<java.lang.Void> |
send(StreamElement element)
Sends an element to the peer entity.
|
java.lang.String |
toString() |
java.util.concurrent.CompletableFuture<java.lang.Void> |
write(StreamElement streamElement)
Writes the element to the stream without really sending it.
|
close, closeAsync, closeAsync, getConfiguration, getStreamId
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
close, closeAsync, closeAsync, getConfiguration, getStreamId
public SocketConnection(java.net.Socket socket, XmppSession xmppSession, TcpConnectionConfiguration configuration)
public final java.util.concurrent.CompletionStage<java.lang.Void> open(SessionOpen sessionOpen)
Connection
Opens the XML stream to the peer entity.
open
in interface Connection
sessionOpen
- The session open information.public boolean isSecure()
Connection
Indicates whether this connection is secured by TLS/SSL.
isSecure
in interface Connection
public void secureConnection() throws java.io.IOException, java.security.cert.CertificateException, java.security.NoSuchAlgorithmException
This method is called from the reader thread. Because it accesses shared data (socket, outputStream, inputStream) it should be synchronized.
secureConnection
in interface TcpBinding
java.io.IOException
java.security.cert.CertificateException
java.security.NoSuchAlgorithmException
public void compressConnection(java.lang.String method, java.lang.Runnable onSuccess) throws java.lang.Exception
TcpBinding
Compresses the connection.
compressConnection
in interface TcpBinding
method
- The compression method.onSuccess
- Invoked after the compression method has been chosen, but before compression is applied.java.lang.Exception
public final java.util.concurrent.CompletableFuture<java.lang.Void> send(StreamElement element)
Connection
send
in interface Connection
element
- The element.public final java.util.concurrent.CompletableFuture<java.lang.Void> write(StreamElement streamElement)
Connection
Writes the element to the stream without really sending it. It must be flushed.
write
in interface Connection
streamElement
- The element.public final void flush()
Connection
Flushes the connection. Any buffered elements written via Connection.write(StreamElement)
are sent.
flush
in interface Connection
public final java.util.concurrent.CompletionStage<java.lang.Void> closeFuture()
Connection
Returns a future which is complete, when the connection is closed.
closeFuture
in interface Connection
public final java.net.InetSocketAddress getRemoteAddress()
Connection
Gets the remote address of this connection.
getRemoteAddress
in interface Connection
public final boolean isUsingAcknowledgements()
Connection
Indicates whether this connection uses acknowledgements, e.g. by means of stream management or BOSH acks.
isUsingAcknowledgements
in interface Connection
isUsingAcknowledgements
in class AbstractConnection
public final java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2014–2019 XMPP.rocks. All rights reserved.