|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Untamed: Interface of methods to get/set socket options. This interface is implemented by: SocketImpl and DatagramSocketImpl. Subclasses of these should override the methods of this interface in order to support their own options.
The methods and constants which specify options in this interface are for implementation only. If you're not subclassing SocketImpl or DatagramSocketImpl, you won't use these directly. There are type-safe methods to get/set each of these options in Socket, ServerSocket, DatagramSocket and MulticastSocket.
Field Summary | |
static int |
IP_MULTICAST_IF
Enabled: Set which outgoing interface on which to send multicast packets. |
static int |
IP_MULTICAST_IF2
Enabled: Same as above. |
static int |
IP_MULTICAST_LOOP
Enabled: This option enables or disables local loopback of multicast datagrams. |
static int |
IP_TOS
Enabled: This option sets the type-of-service or traffic class field in the IP header for a TCP or UDP socket. |
static int |
SO_BINDADDR
Enabled: Fetch the local address binding of a socket (this option cannot be "set" only "gotten", since sockets are bound at creation time, and so the locally bound address cannot be changed). |
static int |
SO_BROADCAST
Enabled: Sets SO_BROADCAST for a socket. |
static int |
SO_KEEPALIVE
Enabled: When the keepalive option is set for a TCP socket and no data has been exchanged across the socket in either direction for 2 hours (NOTE: the actual value is implementation dependent), TCP automatically sends a keepalive probe to the peer. |
static int |
SO_LINGER
Enabled: Specify a linger-on-close timeout. |
static int |
SO_OOBINLINE
Enabled: When the OOBINLINE option is set, any TCP urgent data received on the socket will be received through the socket input stream. |
static int |
SO_RCVBUF
Enabled: Set a hint the size of the underlying buffers used by the platform for incoming network I/O. |
static int |
SO_REUSEADDR
Enabled: Sets SO_REUSEADDR for a socket. |
static int |
SO_SNDBUF
Enabled: Set a hint the size of the underlying buffers used by the platform for outgoing network I/O. |
static int |
SO_TIMEOUT
Enabled: Set a timeout on blocking Socket operations: |
static int |
TCP_NODELAY
Enabled: Disable Nagle's algorithm for this connection. |
Method Summary | |
Object |
getOption(int optID)
Enabled: Fetch the value of an option. |
void |
setOption(int optID,
Object value)
Enabled: Enable/disable the option specified by optID. |
Field Detail |
public static final int TCP_NODELAY
Valid for TCP only: SocketImpl.
Socket.setTcpNoDelay(boolean)
,
Socket.getTcpNoDelay()
public static final int SO_BINDADDR
This option must be specified in the constructor.
Valid for: SocketImpl, DatagramSocketImpl
Socket.getLocalAddress()
,
DatagramSocket.getLocalAddress()
public static final int SO_REUSEADDR
Valid for: DatagramSocketImpl
public static final int SO_BROADCAST
public static final int IP_MULTICAST_IF
Valid for Multicast: DatagramSocketImpl
MulticastSocket.setInterface(InetAddress)
,
MulitcastSocket#getInterface()
public static final int IP_MULTICAST_IF2
MulticastSocket.setNetworkInterface(NetworkInterface)
,
MulticastSocket.getNetworkInterface()
public static final int IP_MULTICAST_LOOP
public static final int IP_TOS
public static final int SO_LINGER
Valid only for TCP: SocketImpl
Socket.setSoLinger(boolean, int)
,
Socket.getSoLinger()
public static final int SO_TIMEOUT
ServerSocket.accept(); SocketInputStream.read(); DatagramSocket.receive();
The option must be set prior to entering a blocking operation to take effect. If the timeout expires and the operation would continue to block, java.io.InterruptedIOException is raised. The Socket is not closed in this case.
Valid for all sockets: SocketImpl, DatagramSocketImpl
Socket.setSoTimeout(int)
,
ServerSocket.setSoTimeout(int)
,
DatagramSocket.setSoTimeout(int)
public static final int SO_SNDBUF
Socket.setSendBufferSize(int)
,
Socket.getSendBufferSize()
,
DatagramSocket.setSendBufferSize(int)
,
DatagramSocket.getSendBufferSize()
public static final int SO_RCVBUF
Socket.setReceiveBufferSize(int)
,
Socket.getReceiveBufferSize()
,
DatagramSocket.setReceiveBufferSize(int)
,
DatagramSocket.getReceiveBufferSize()
public static final int SO_KEEPALIVE
Socket.setKeepAlive(boolean)
,
Socket.getKeepAlive()
public static final int SO_OOBINLINE
Socket.setOOBInline(boolean)
,
Socket.getOOBInline()
Method Detail |
public void setOption(int optID, Object value) throws SocketException
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.IntegerIf 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 occurredgetOption(int)
public Object getOption(int optID) throws SocketException
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 closed
SocketException
- if optID is unknown along the
protocol stack (including the SocketImpl)setOption(int, java.lang.Object)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |