public class NetworkInterface
extends java.lang.Object
implements java.io.Closeable
ServerSocket
that can handle multiple bind addresses
and allows IP address level filtering.Modifier and Type | Field and Description |
---|---|
protected AllowedHosts |
allowedHosts
AllowedHosts structure
|
static java.lang.String |
DEFAULT_BIND_TO |
Modifier | Constructor and Description |
---|---|
protected |
NetworkInterface(int port,
java.lang.String allowedHosts,
Executor executor)
Creates a new network interface that can bind to several addresses and
allows connection filtering on IP address level.
|
Modifier and Type | Method and Description |
---|---|
java.net.Socket |
accept()
Waits for a connection.
|
void |
close()
Closes this interface and all underlying server sockets.
|
static NetworkInterface |
create(int port,
java.lang.String bindTo,
java.lang.String allowedHosts,
Executor executor,
boolean ignoreUnbindableIP6) |
protected java.net.ServerSocket |
createServerSocket() |
java.lang.String |
getAllowedHosts() |
boolean |
isBound() |
void |
setAllowedHosts(java.lang.String allowedHosts) |
java.lang.String[] |
setBindTo(java.lang.String bindTo,
boolean ignoreUnbindableIP6)
Sets the list of IP address this network interface binds to.
|
void |
setSoTimeout(int timeout)
Sets the SO_TIMEOUT value on the server sockets.
|
void |
waitBound() |
public static final java.lang.String DEFAULT_BIND_TO
protected final AllowedHosts allowedHosts
protected NetworkInterface(int port, java.lang.String allowedHosts, Executor executor) throws java.io.IOException
bindTo
- A comma-separated list of addresses to bind toallowedHosts
- A comma-separated list of allowed addressesjava.io.IOException
public static NetworkInterface create(int port, java.lang.String bindTo, java.lang.String allowedHosts, Executor executor, boolean ignoreUnbindableIP6) throws java.io.IOException
java.io.IOException
protected java.net.ServerSocket createServerSocket() throws java.io.IOException
java.io.IOException
public java.lang.String[] setBindTo(java.lang.String bindTo, boolean ignoreUnbindableIP6)
bindTo
- A comma-separated list of IP address to bind topublic void setAllowedHosts(java.lang.String allowedHosts)
public void setSoTimeout(int timeout) throws java.net.SocketException
timeout
- The timeout in milliseconds, 0
to disablejava.net.SocketException
- if the SO_TIMEOUT value can not be setServerSocket.setSoTimeout(int)
public java.net.Socket accept()
setSoTimeout(int)
and no connection is established this method
will return after the specified timeout has been expired, throwing a
SocketTimeoutException
. If no timeout has been set this method
will wait until a connection has been established.public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
- if an I/O exception occursServerSocket.close()
public java.lang.String getAllowedHosts()
public boolean isBound()
public void waitBound()