Package biz.onixs.util.network
Interface SocketConnector
-
- All Superinterfaces:
AutoCloseable
public interface SocketConnector extends AutoCloseable
The interface provides methods for creating socket connections.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classSocketConnector.ErrorReasonAn enum that defines reasons for socket connecting errors.static interfaceSocketConnector.ListenerThe interface represents a listener for handling connect events.
-
Field Summary
Fields Modifier and Type Field Description static SocketConnector.ListenerNULL_LISTENERThis field represents a dummy implementation of theSocketConnector.Listenerinterface.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Socketconnect()Synchronous connection attempt.voidconnectAfterInterval(long interval, TimeUnit timeUnit)Initiates a connection attempt after a specified interval.voidconnectAsync()Initiates an asynchronous connection attempt.StringgetHost()Returns the hostname or IP address to connect.intgetPort()Returns the port number to connect.voidsetListener(SocketConnector.Listener listener)Sets the listener for this socket connector.voidstopConnectAfterInterval()Stops a previously scheduled connection attempt viaconnectAfterInterval(long, TimeUnit).-
Methods inherited from interface java.lang.AutoCloseable
close
-
-
-
-
Field Detail
-
NULL_LISTENER
static final SocketConnector.Listener NULL_LISTENER
This field represents a dummy implementation of theSocketConnector.Listenerinterface.
-
-
Method Detail
-
getHost
String getHost()
Returns the hostname or IP address to connect.- Returns:
- the hostname or IP address to connect
-
getPort
int getPort()
Returns the port number to connect.- Returns:
- the port number to connect
-
setListener
void setListener(SocketConnector.Listener listener)
Sets the listener for this socket connector.- Parameters:
listener- the listener to use for connection events
-
connect
Socket connect() throws IOException
Synchronous connection attempt.- Returns:
- connected socket.
- Throws:
IOException- if an error occurs during the binding/connection.
-
connectAsync
void connectAsync()
Initiates an asynchronous connection attempt.
-
connectAfterInterval
void connectAfterInterval(long interval, TimeUnit timeUnit)Initiates a connection attempt after a specified interval.- Parameters:
interval- the length of the intervaltimeUnit- the time unit for the interval
-
stopConnectAfterInterval
void stopConnectAfterInterval()
Stops a previously scheduled connection attempt viaconnectAfterInterval(long, TimeUnit).
-
-