|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.net.SocketImpl
org.tentackle.net.SocketImplWrapper
public class SocketImplWrapper
A wrapping SocketImpl.
Nice to wrap SSL sockets to add compression, for example.
Notice that wrapped sockets are always connected/bound!
| Field Summary |
|---|
| Fields inherited from class java.net.SocketImpl |
|---|
address, fd, localport, port |
| Fields inherited from interface java.net.SocketOptions |
|---|
IP_MULTICAST_IF, IP_MULTICAST_IF2, IP_MULTICAST_LOOP, IP_TOS, SO_BINDADDR, SO_BROADCAST, SO_KEEPALIVE, SO_LINGER, SO_OOBINLINE, SO_RCVBUF, SO_REUSEADDR, SO_SNDBUF, SO_TIMEOUT, TCP_NODELAY |
| Constructor Summary | |
|---|---|
SocketImplWrapper(Socket socket)
Creates an impl wrapper that delegates all method invocations to the wrapped socket. |
|
| Method Summary | |
|---|---|
protected void |
accept(SocketImpl s)
Accepts a connection. |
protected int |
available()
Returns the number of bytes that can be read from this socket without blocking. |
protected void |
bind(InetAddress host,
int port)
Binds this socket to the specified local IP address and port number. |
protected void |
close()
Closes this socket. |
protected void |
connect(InetAddress address,
int port)
Connects this socket to the specified port number on the specified host. |
protected void |
connect(SocketAddress address,
int timeout)
Connects this socket to the specified port number on the specified host. |
protected void |
connect(String host,
int port)
Connects this socket to the specified port on the named host. |
protected void |
create(boolean stream)
Creates either a stream or a datagram socket. |
protected FileDescriptor |
getFileDescriptor()
Returns the value of this socket's fd field. |
protected InetAddress |
getInetAddress()
Returns the value of this socket's address field. |
protected InputStream |
getInputStream()
Returns an input stream for this socket. |
protected int |
getLocalPort()
Returns the value of this socket's localport field. |
Object |
getOption(int optID)
Fetch the value of an option. |
protected OutputStream |
getOutputStream()
Returns an output stream for this socket. |
protected int |
getPort()
Returns the value of this socket's port field. |
protected void |
listen(int backlog)
Sets the maximum queue length for incoming connection indications (a request to connect) to the count argument. |
protected void |
sendUrgentData(int data)
Send one byte of urgent data on the socket. |
void |
setOption(int optID,
Object value)
Enable/disable the option specified by optID. |
protected void |
shutdownInput()
Places the input stream for this socket at "end of stream". |
protected void |
shutdownOutput()
Disables the output stream for this socket. |
| Methods inherited from class java.net.SocketImpl |
|---|
setPerformancePreferences, supportsUrgentData, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public SocketImplWrapper(Socket socket)
socket - the socket to wrap| Method Detail |
|---|
protected void shutdownInput()
throws IOException
java.net.SocketImpl
shutdownInput in class SocketImplIOException - if an I/O error occurs when shutting down this
socket.Socket.shutdownOutput(),
Socket.close(),
Socket.setSoLinger(boolean, int)
protected void shutdownOutput()
throws IOException
java.net.SocketImpl
shutdownOutput in class SocketImplIOException - if an I/O error occurs when shutting down this
socket.Socket.shutdownInput(),
Socket.close(),
Socket.setSoLinger(boolean, int)protected FileDescriptor getFileDescriptor()
java.net.SocketImplfd field.
getFileDescriptor in class SocketImplfd field.SocketImpl.fdprotected InetAddress getInetAddress()
java.net.SocketImpladdress field.
getInetAddress in class SocketImpladdress field.SocketImpl.addressprotected int getPort()
java.net.SocketImplport field.
getPort in class SocketImplport field.SocketImpl.portprotected int getLocalPort()
java.net.SocketImpllocalport field.
getLocalPort in class SocketImpllocalport field.SocketImpl.localport
protected void create(boolean stream)
throws IOException
java.net.SocketImpl
create in class SocketImplstream - if true, create a stream socket;
otherwise, create a datagram socket.
IOException - if an I/O error occurs while creating the
socket.
protected void connect(String host,
int port)
throws IOException
java.net.SocketImpl
connect in class SocketImplhost - the name of the remote host.port - the port number.
IOException - if an I/O error occurs when connecting to the
remote host.
protected void connect(InetAddress address,
int port)
throws IOException
java.net.SocketImpl
connect in class SocketImpladdress - the IP address of the remote host.port - the port number.
IOException - if an I/O error occurs when attempting a
connection.
protected void connect(SocketAddress address,
int timeout)
throws IOException
java.net.SocketImpl
connect in class SocketImpladdress - the Socket address of the remote host.timeout - the timeout value, in milliseconds, or zero for no timeout.
IOException - if an I/O error occurs when attempting a
connection.
protected void bind(InetAddress host,
int port)
throws IOException
java.net.SocketImpl
bind in class SocketImplhost - an IP address that belongs to a local interface.port - the port number.
IOException - if an I/O error occurs when binding this socket.
protected void listen(int backlog)
throws IOException
java.net.SocketImplcount argument. If a
connection indication arrives when the queue is full, the
connection is refused.
listen in class SocketImplbacklog - the maximum length of the queue.
IOException - if an I/O error occurs when creating the queue.
protected void accept(SocketImpl s)
throws IOException
java.net.SocketImpl
accept in class SocketImpls - the accepted connection.
IOException - if an I/O error occurs when accepting the
connection.
protected InputStream getInputStream()
throws IOException
java.net.SocketImpl
getInputStream in class SocketImplIOException - if an I/O error occurs when creating the
input stream.
protected OutputStream getOutputStream()
throws IOException
java.net.SocketImpl
getOutputStream in class SocketImplIOException - if an I/O error occurs when creating the
output stream.
protected int available()
throws IOException
java.net.SocketImpl
available in class SocketImplIOException - if an I/O error occurs when determining the
number of bytes available.
protected void close()
throws IOException
java.net.SocketImpl
close in class SocketImplIOException - if an I/O error occurs when closing this socket.
protected void sendUrgentData(int data)
throws IOException
java.net.SocketImpl
sendUrgentData in class SocketImpldata - The byte of data to send
IOException - if there is an error
sending the data.
public void setOption(int optID,
Object value)
throws SocketException
java.net.SocketOptions
SocketImpl s;
...
s.setOption(SO_LINGER, new Integer(10));
// OK - set SO_LINGER w/ timeout of 10 sec.
s.setOption(SO_LINGER, new Double(10));
// ERROR - expects java.lang.Integer
If the requested option is binary, it can be set using this method by
a java.lang.Boolean:
s.setOption(TCP_NODELAY, new Boolean(true));
// OK - enables TCP_NODELAY, a binary option
s.setOption(TCP_NODELAY, new Boolean(false));
// OK - disables TCP_NODELAY
s.setOption(SO_LINGER, new Boolean(false));
// OK - disables SO_LINGER
optID - identifies the optionvalue - the parameter of the socket option
SocketException - if the option is unrecognized,
the socket is closed, or some low-level error occurredSocketOptions.getOption(int)
public Object getOption(int optID)
throws SocketException
java.net.SocketOptions
SocketImpl s;
...
Boolean noDelay = (Boolean)(s.getOption(TCP_NODELAY));
if (noDelay.booleanValue()) {
// true if TCP_NODELAY is enabled...
...
}
For options that take a particular type as a parameter, getOption(int) will return the paramter's value, else it will return java.lang.Boolean(false):
Object o = s.getOption(SO_LINGER);
if (o instanceof Integer) {
System.out.print("Linger time is " + ((Integer)o).intValue());
} else {
// the true type of o is java.lang.Boolean(false);
}
optID - an int identifying the option to fetch
SocketException - if the socket is closedSocketOptions.setOption(int, java.lang.Object)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||