Class SocketConnection
- java.lang.Object
-
- org.simpleframework.transport.connect.SocketConnection
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,Connection
public class SocketConnection extends java.lang.Object implements Connection
TheSocketConnectionis used to manage connections from a server socket. In order to achieve this it spawns a task to listen for incoming connect requests. When a TCP connection request arrives it hands off theSocketChannelto theSocketProcessorwhich processes the request.This handles connections from a
ServerSocketChannelobject so that features such as SSL can be used by a server that uses this package. The background acceptor process will terminate if the connection is closed.- Author:
- Niall Gallagher
- See Also:
SocketProcessor
-
-
Constructor Summary
Constructors Constructor Description SocketConnection(SocketProcessor processor)Constructor for theSocketConnectionobject.SocketConnection(SocketProcessor processor, TraceAnalyzer analyzer)Constructor for theSocketConnectionobject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()This is used to close the connection and the server socket used to accept connections.java.net.SocketAddressconnect(java.net.SocketAddress address)This creates a new background task that will listen to the specifiedServerAddressfor incoming TCP connect requests.java.net.SocketAddressconnect(java.net.SocketAddress address, javax.net.ssl.SSLContext context)This creates a new background task that will listen to the specifiedServerAddressfor incoming TCP connect requests.
-
-
-
Constructor Detail
-
SocketConnection
public SocketConnection(SocketProcessor processor) throws java.io.IOException
Constructor for theSocketConnectionobject. This will create a new connection that accepts incoming connections and hands these connections asSocketobjects to the specified connector. This in turn will deliver request and response objects to the internal container.- Parameters:
processor- this is the connector that receives requests- Throws:
java.io.IOException
-
SocketConnection
public SocketConnection(SocketProcessor processor, TraceAnalyzer analyzer) throws java.io.IOException
Constructor for theSocketConnectionobject. This will create a new connection that accepts incoming connections and hands these connections asSocketobjects to the specified processor. This in turn will deliver request and response objects to the internal container.- Parameters:
processor- this is the connector that receives requestsanalyzer- this is used to create a trace for the socket- Throws:
java.io.IOException
-
-
Method Detail
-
connect
public java.net.SocketAddress connect(java.net.SocketAddress address) throws java.io.IOExceptionThis creates a new background task that will listen to the specifiedServerAddressfor incoming TCP connect requests. When an connection is accepted it is handed to the internal socket connector.- Specified by:
connectin interfaceConnection- Parameters:
address- this is the address used to accept connections- Returns:
- this returns the actual local address that is used
- Throws:
java.io.IOException
-
connect
public java.net.SocketAddress connect(java.net.SocketAddress address, javax.net.ssl.SSLContext context) throws java.io.IOExceptionThis creates a new background task that will listen to the specifiedServerAddressfor incoming TCP connect requests. When an connection is accepted it is handed to the internal socket connector.- Specified by:
connectin interfaceConnection- Parameters:
address- this is the address used to accept connectionscontext- this is used for secure SSL connections- Returns:
- this returns the actual local address that is used
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOExceptionThis is used to close the connection and the server socket used to accept connections. This will perform a close of all connected server sockets that have been created from using theconnectmethod. The connection can be reused after the existing server sockets have been closed.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException- thrown if there is a problem closing
-
-