默认方式我没研究过
不过你可以试一下
java.net Interface SocketOptions
中的getOption() setOption()方法
用法如下
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
Any option can be disabled using this method with a Boolean(false): s.setOption(TCP_NODELAY, new Boolean(false));
// OK - disables TCP_NODELAY
s.setOption(SO_LINGER, new Boolean(false));
// OK - disables SO_LINGER
//getOption 用法
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);
}
//以下是参数解释,我没翻,自己看看,是不是要的static int IP_MULTICAST_IF
Set which outgoing interface on which to send multicast packets.
static int SO_BINDADDR
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_KEEPALIVE
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
Specify a linger-on-close timeout.static intSO_RCVBUF Set a hint the size of the underlying buffers used by the platform for incoming network I/O.
static int SO_REUSEADDR
Sets SO_REUSEADDR for a socket.
static int SO_SNDBUF
Set a hint the size of the underlying buffers used by the platform for outgoing network I/O.static intSO_TIMEOUT Set a timeout on blocking Socket operations:
static int TCP_NODELAY
Disable Nagle's algorithm for this connection
不过你可以试一下
java.net Interface SocketOptions
中的getOption() setOption()方法
用法如下
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
Any option can be disabled using this method with a Boolean(false): s.setOption(TCP_NODELAY, new Boolean(false));
// OK - disables TCP_NODELAY
s.setOption(SO_LINGER, new Boolean(false));
// OK - disables SO_LINGER
//getOption 用法
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);
}
//以下是参数解释,我没翻,自己看看,是不是要的static int IP_MULTICAST_IF
Set which outgoing interface on which to send multicast packets.
static int SO_BINDADDR
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_KEEPALIVE
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
Specify a linger-on-close timeout.static intSO_RCVBUF Set a hint the size of the underlying buffers used by the platform for incoming network I/O.
static int SO_REUSEADDR
Sets SO_REUSEADDR for a socket.
static int SO_SNDBUF
Set a hint the size of the underlying buffers used by the platform for outgoing network I/O.static intSO_TIMEOUT Set a timeout on blocking Socket operations:
static int TCP_NODELAY
Disable Nagle's algorithm for this connection
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货