|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.net.ServerSocket
jhomenet.commons.net.secure.ServerSocketMonitor
public class ServerSocketMonitor
Wraps an SSLServerSocket instance to intercept accept() invocations and wrap the result in a SocketMonitor object.
ServerSocket,
SSLServerSocket| Field Summary | |
|---|---|
protected javax.net.ssl.SSLServerSocket |
server
The wrapped socket |
| Constructor Summary | |
|---|---|
ServerSocketMonitor(javax.net.ssl.SSLServerSocket server)
Construct a new SSLServerSocket wrapper over the real SSLServerSocket instance. |
|
| Method Summary | |
|---|---|
java.net.Socket |
accept()
Listens for a connection to be made to this socket and accepts it. |
void |
bind(java.net.SocketAddress endpoint)
Binds the ServerSocket to a specific address
(IP address and port number). |
void |
bind(java.net.SocketAddress endpoint,
int backlog)
Binds the ServerSocket to a specific address
(IP address and port number). |
void |
close()
Closes this socket. |
java.nio.channels.ServerSocketChannel |
getChannel()
Returns the unique ServerSocketChannel object
associated with this socket, if any. |
java.net.InetAddress |
getInetAddress()
Returns the local address of this server socket. |
int |
getLocalPort()
Returns the port on which this socket is listening. |
java.net.SocketAddress |
getLocalSocketAddress()
Returns the address of the endpoint this socket is bound to, or null if it is not bound yet. |
int |
getReceiveBufferSize()
Gets the value of the SO_RCVBUF option for this ServerSocket, that is the proposed buffer size that will be used for Sockets accepted from this ServerSocket. |
boolean |
getReuseAddress()
Tests if SO_REUSEADDR is enabled. |
int |
getSoTimeout()
Retrive setting for SO_TIMEOUT. |
boolean |
isBound()
Returns the binding state of the ServerSocket. |
boolean |
isClosed()
Returns the closed state of the ServerSocket. |
void |
setReceiveBufferSize(int size)
Sets a default proposed value for the SO_RCVBUF option for sockets accepted from this ServerSocket. |
void |
setReuseAddress(boolean on)
Enable/disable SO_REUSEADDR. |
void |
setSoTimeout(int timeout)
Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. |
java.lang.String |
toString()
Returns the implementation address and implementation port of this socket as a String. |
| Methods inherited from class java.net.ServerSocket |
|---|
implAccept, setPerformancePreferences, setSocketFactory |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected final javax.net.ssl.SSLServerSocket server
| Constructor Detail |
|---|
public ServerSocketMonitor(javax.net.ssl.SSLServerSocket server)
throws java.io.IOException
The ServerSocket object did not provide a public no-arg constructor
prior to JDK 1.4. As a result, this constructor will invoke the
super(0) to create a server socket and will then
close it right away. This may interfere with a security policy
restricting listen permission to certain ports.
This class may be recompiled without the first two lines if it is only going to be used in JDK > 1.4
java.io.IOException| Method Detail |
|---|
public void bind(java.net.SocketAddress endpoint)
throws java.io.IOException
ServerSocket to a specific address
(IP address and port number).
If the address is null, then the system will pick up
an ephemeral port and a valid local address to bind the socket.
bind in class java.net.ServerSocketendpoint - The IP address & port number to bind to.
java.io.IOException - if the bind operation fails, or if the socket
is already bound.
java.lang.SecurityException - if a SecurityManager is present and
its checkListen method doesn't allow the operation.
java.lang.IllegalArgumentException - if endpoint is a
SocketAddress subclass not supported by this socket
public void bind(java.net.SocketAddress endpoint,
int backlog)
throws java.io.IOException
ServerSocket to a specific address
(IP address and port number).
If the address is null, then the system will pick up
an ephemeral port and a valid local address to bind the socket.
The backlog argument must be a positive
value greater than 0. If the value passed if equal or less
than 0, then the default value will be assumed.
bind in class java.net.ServerSocketendpoint - The IP address & port number to bind to.backlog - The listen backlog length.
java.io.IOException - if the bind operation fails, or if the socket
is already bound.
java.lang.SecurityException - if a SecurityManager is present and
its checkListen method doesn't allow the operation.
java.lang.IllegalArgumentException - if endpoint is a
SocketAddress subclass not supported by this socketpublic java.net.InetAddress getInetAddress()
getInetAddress in class java.net.ServerSocketnull if the socket is not yet connected.public int getLocalPort()
getLocalPort in class java.net.ServerSocketpublic java.net.SocketAddress getLocalSocketAddress()
null if it is not bound yet.
getLocalSocketAddress in class java.net.ServerSocketSocketAddress representing the local endpoint of this
socket, or null if it is not bound yet.getInetAddress(),
getLocalPort(),
bind(SocketAddress)
public java.net.Socket accept()
throws java.io.IOException
A new Socket s is created and, if there
is a security manager,
the security manager's checkAccept method is called
with s.getInetAddress().getHostAddress() and
s.getPort()
as its arguments to ensure the operation is allowed.
This could result in a SecurityException.
accept in class java.net.ServerSocketjava.io.IOException - if an I/O error occurs when waiting for a
connection.
java.lang.SecurityException - if a security manager exists and its
checkListen method doesn't allow the operation.SecurityManager.checkAccept(java.lang.String, int)
public void close()
throws java.io.IOException
close in class java.net.ServerSocketjava.io.IOException - if an I/O error occurs when closing the socket.public java.nio.channels.ServerSocketChannel getChannel()
ServerSocketChannel object
associated with this socket, if any.
A server socket will have a channel if, and only if, the channel
itself was created via the ServerSocketChannel.open
method.
getChannel in class java.net.ServerSocketpublic boolean isBound()
isBound in class java.net.ServerSocketpublic boolean isClosed()
isClosed in class java.net.ServerSocket
public void setSoTimeout(int timeout)
throws java.net.SocketException
setSoTimeout in class java.net.ServerSockettimeout - the specified timeout, in milliseconds
java.net.SocketException - if there is an error in
the underlying protocol, such as a TCP error.getSoTimeout()
public int getSoTimeout()
throws java.io.IOException
getSoTimeout in class java.net.ServerSocketjava.io.IOException - if an I/O error occurssetSoTimeout(int)
public void setReuseAddress(boolean on)
throws java.net.SocketException
The SO_REUSEADDR socket option affects the bind()
operation and serves 2 main different purposes:
bind its port
even if previously established connections exists that use this port
as their local port. This typically happens when a ServerSocket is
started and listen on that port, accepts an incoming connection and
spawn a child process to handle the socket. Then the listening server
terminates but the child continues to service the client. At that, to
be able to restart the listening ServerSocket, the SO_REUSEADDR option
needs to be turned on.
setReuseAddress in class java.net.ServerSocketon - whether or not to have socket ReuseAddr turned on.
java.net.SocketException - if there is an error
in the underlying protocol, such as a TCP error.getReuseAddress()
public boolean getReuseAddress()
throws java.net.SocketException
getReuseAddress in class java.net.ServerSocketboolean indicating whether or not SO_REUSEADDR is enabled.
java.net.SocketException - if there is an error
in the underlying protocol, such as a TCP error.setReuseAddress(boolean)public java.lang.String toString()
String.
toString in class java.net.ServerSocket
public void setReceiveBufferSize(int size)
throws java.net.SocketException
Socket.getReceiveBufferSize() after the socket
is returned by accept().
The value of SO_RCVBUF is used both to set the size of the internal socket receive buffer, and to set the size of the TCP receive window that is advertized to the remote peer.
It is possible to change the value subsequently, by calling
Socket.setReceiveBufferSize(int). However, if the application
wishes to allow a receive window larger than 64K bytes, as defined by RFC1323
then the proposed value must be set in the ServerSocket before
it is bound to a local address. This implies, that the ServerSocket must be
created with the no-argument constructor, then setReceiveBufferSize() must
be called and lastly the ServerSocket is bound to an address by calling bind().
Failure to do this will not cause an error, and the buffer size may be set to the requested value but the TCP receive window in sockets accepted from this ServerSocket will be no larger than 64K bytes.
setReceiveBufferSize in class java.net.ServerSocketsize - the size to which to set the receive buffer
size. This value must be greater than 0.
java.net.SocketException - if there is an error
in the underlying protocol, such as a TCP error.
java.lang.IllegalArgumentException - if the
value is 0 or is negative.getReceiveBufferSize()
public int getReceiveBufferSize()
throws java.net.SocketException
Note, the value actually set in the accepted socket is determined by
calling Socket.getReceiveBufferSize().
getReceiveBufferSize in class java.net.ServerSocketjava.net.SocketException - if there is an error
in the underlying protocol, such as a TCP error.setReceiveBufferSize(int)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||