本文整理汇总了Java中java.net.StandardSocketOptions类的典型用法代码示例。如果您正苦于以下问题:Java StandardSocketOptions类的具体用法?Java StandardSocketOptions怎么用?Java StandardSocketOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StandardSocketOptions类属于java.net包,在下文中一共展示了StandardSocketOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: JdpBroadcaster
import java.net.StandardSocketOptions; //导入依赖的package包/类
/**
* Create a new broadcaster
*
* @param address - multicast group address
* @param srcAddress - address of interface we should use to broadcast.
* @param port - udp port to use
* @param ttl - packet ttl
* @throws IOException
*/
public JdpBroadcaster(InetAddress address, InetAddress srcAddress, int port, int ttl)
throws IOException, JdpException {
this.addr = address;
this.port = port;
ProtocolFamily family = (address instanceof Inet6Address)
? StandardProtocolFamily.INET6 : StandardProtocolFamily.INET;
channel = DatagramChannel.open(family);
channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
channel.setOption(StandardSocketOptions.IP_MULTICAST_TTL, ttl);
// with srcAddress equal to null, this constructor do exactly the same as
// if srcAddress is not passed
if (srcAddress != null) {
// User requests particular interface to bind to
NetworkInterface interf = NetworkInterface.getByInetAddress(srcAddress);
try {
channel.bind(new InetSocketAddress(srcAddress, 0));
} catch (UnsupportedAddressTypeException ex) {
throw new JdpException("Unable to bind to source address");
}
channel.setOption(StandardSocketOptions.IP_MULTICAST_IF, interf);
}
}
示例2: NIOAcceptor
import java.net.StandardSocketOptions; //导入依赖的package包/类
public NIOAcceptor(String name, String bindIp,int port,
FrontendConnectionFactory factory, NIOReactorPool reactorPool)
throws IOException {
super.setName(name);
this.port = port;
this.selector = Selector.open();
this.serverChannel = ServerSocketChannel.open();
this.serverChannel.configureBlocking(false);
/** 设置TCP属性 */
serverChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
serverChannel.setOption(StandardSocketOptions.SO_RCVBUF, 1024 * 16 * 2);
// backlog=100
serverChannel.bind(new InetSocketAddress(bindIp, port), 100);
// 注册OP_ACCEPT,监听客户端连接 // 准备好接受新的连接 // 监听到之后是图-MySql第2步,(接受TCP连接)
this.serverChannel.register(selector, SelectionKey.OP_ACCEPT);
//FrontendConnectionFactory,用来封装channel成为FrontendConnection
this.factory = factory;
//NIOReactor池
this.reactorPool = reactorPool;
}
示例3: SetRcvBufferSize
import java.net.StandardSocketOptions; //导入依赖的package包/类
/**
* This method sets the receiving buffer size of the {@link SocketChannel} wrapped by this {@link RapidConnection}
* @param size Size of the receiving buffer size of the {@link SocketChannel} wrapped by this {@link RapidConnection}
*/
public void SetRcvBufferSize(int size)
{
if(connected)
{
try
{
socketchannel.setOption(StandardSocketOptions.SO_RCVBUF, size);
}
catch (IOException e)
{
if(infoANDdebug.getDEBUG())
{
e.printStackTrace();
}
}
}
}
示例4: SetSndBufferSize
import java.net.StandardSocketOptions; //导入依赖的package包/类
/**
* This method sets the sending buffer size of the {@link SocketChannel} wrapped by this {@link RapidConnection}
* @param size Size of the sending buffer size of the {@link SocketChannel} wrapped by this {@link RapidConnection}
*/
public void SetSndBufferSize(int size)
{
if(connected)
{
try
{
socketchannel.setOption(StandardSocketOptions.SO_SNDBUF, size);
}
catch (IOException e)
{
if(infoANDdebug.getDEBUG())
{
e.printStackTrace();
}
}
}
}
示例5: SetNoDelay
import java.net.StandardSocketOptions; //导入依赖的package包/类
/**
* This method sets the TCP_NO_DELAY of the {@link SocketChannel} wrapped by this {@link RapidConnection}
* @param b The value of the TCP_NO_DELAY parameter of the {@link SocketChannel} wrapped by this {@link RapidConnection}
*/
public void SetNoDelay(boolean b)
{
if(connected)
{
try
{
socketchannel.setOption(StandardSocketOptions.TCP_NODELAY, b);
}
catch (IOException e)
{
if(infoANDdebug.getDEBUG())
{
e.printStackTrace();
}
}
}
}
示例6: GetRcvBufferSize
import java.net.StandardSocketOptions; //导入依赖的package包/类
/**
* This method returns the receiving buffer size of the {@link SocketChannel} wrapped by this {@link RapidConnection}
* @return The Size of the receiving buffer size of the {@link SocketChannel} wrapped by this {@link RapidConnection}
*/
public int GetRcvBufferSize()
{
if(connected)
{
try
{
return socketchannel.getOption(StandardSocketOptions.SO_RCVBUF);
}
catch (IOException e)
{
if(infoANDdebug.getDEBUG())
{
e.printStackTrace();
}
}
}
return -1;
}
示例7: GetSndBufferSize
import java.net.StandardSocketOptions; //导入依赖的package包/类
/**
* This method returns the sending buffer size of the {@link SocketChannel} wrapped by this {@link RapidConnection}
* @return The Size of the sending buffer size of the {@link SocketChannel} wrapped by this {@link RapidConnection}
*/
public int GetSndBufferSize()
{
if(connected)
{
try
{
return socketchannel.getOption(StandardSocketOptions.SO_SNDBUF);
}
catch (IOException e)
{
if(infoANDdebug.getDEBUG())
{
e.printStackTrace();
}
}
}
return -1;
}
示例8: GetNoDelay
import java.net.StandardSocketOptions; //导入依赖的package包/类
/**
* This method returns the TCP_NO_DELAY of the {@link SocketChannel} wrapped by this {@link RapidConnection}
* @return The value of the TCP_NO_DELAY parameter of the {@link SocketChannel} wrapped by this {@link RapidConnection}
*/
public boolean GetNoDelay()
{
if(connected)
{
try
{
return socketchannel.getOption(StandardSocketOptions.TCP_NODELAY);
}
catch (IOException e)
{
if(infoANDdebug.getDEBUG())
{
e.printStackTrace();
}
}
}
return false;
}
示例9: open
import java.net.StandardSocketOptions; //导入依赖的package包/类
public void open() {
SocketAddress address = new InetSocketAddress(port);
try (
DatagramChannel channel = DatagramChannel.open()
.setOption(StandardSocketOptions.SO_REUSEADDR, true)
.bind(address)
) {
channel.configureBlocking(true);
logger.info("Listening: {}", port);
while (isAlive) {
long sequence = ringBuffer.next();
ByteBufferContainer container = ringBuffer.get(sequence);
container.clear();
channel.receive(container.getBuffer());
container.flip();
ringBuffer.publish(sequence);
}
} catch (Exception e) {
logger.error("Got exception...", e);
}
}
示例10: options
import java.net.StandardSocketOptions; //导入依赖的package包/类
private static Map<RegistryKey,OptionKey> options() {
Map<RegistryKey,OptionKey> map =
new HashMap<RegistryKey,OptionKey>();
map.put(new RegistryKey(StandardSocketOptions.SO_BROADCAST, Net.UNSPEC), new OptionKey(1, 6));
map.put(new RegistryKey(StandardSocketOptions.SO_KEEPALIVE, Net.UNSPEC), new OptionKey(1, 9));
map.put(new RegistryKey(StandardSocketOptions.SO_LINGER, Net.UNSPEC), new OptionKey(1, 13));
map.put(new RegistryKey(StandardSocketOptions.SO_SNDBUF, Net.UNSPEC), new OptionKey(1, 7));
map.put(new RegistryKey(StandardSocketOptions.SO_RCVBUF, Net.UNSPEC), new OptionKey(1, 8));
map.put(new RegistryKey(StandardSocketOptions.SO_REUSEADDR, Net.UNSPEC), new OptionKey(1, 2));
map.put(new RegistryKey(StandardSocketOptions.TCP_NODELAY, Net.UNSPEC), new OptionKey(6, 1));
map.put(new RegistryKey(StandardSocketOptions.IP_TOS, StandardProtocolFamily.INET), new OptionKey(0, 1));
map.put(new RegistryKey(StandardSocketOptions.IP_MULTICAST_IF, StandardProtocolFamily.INET), new OptionKey(0, 32));
map.put(new RegistryKey(StandardSocketOptions.IP_MULTICAST_TTL, StandardProtocolFamily.INET), new OptionKey(0, 33));
map.put(new RegistryKey(StandardSocketOptions.IP_MULTICAST_LOOP, StandardProtocolFamily.INET), new OptionKey(0, 34));
map.put(new RegistryKey(StandardSocketOptions.IP_TOS, StandardProtocolFamily.INET6), new OptionKey(41, 67));
map.put(new RegistryKey(StandardSocketOptions.IP_MULTICAST_IF, StandardProtocolFamily.INET6), new OptionKey(41, 17));
map.put(new RegistryKey(StandardSocketOptions.IP_MULTICAST_TTL, StandardProtocolFamily.INET6), new OptionKey(41, 18));
map.put(new RegistryKey(StandardSocketOptions.IP_MULTICAST_LOOP, StandardProtocolFamily.INET6), new OptionKey(41, 19));
map.put(new RegistryKey(ExtendedSocketOption.SO_OOBINLINE, Net.UNSPEC), new OptionKey(1, 10));
return map;
}
示例11: setOption
import java.net.StandardSocketOptions; //导入依赖的package包/类
@Override
public final <T> AsynchronousServerSocketChannel setOption(SocketOption<T> name,
T value)
throws IOException
{
if (name == null)
throw new NullPointerException();
if (!supportedOptions().contains(name))
throw new UnsupportedOperationException("'" + name + "' not supported");
try {
begin();
if (name == StandardSocketOptions.SO_REUSEADDR &&
Net.useExclusiveBind())
{
// SO_REUSEADDR emulated when using exclusive bind
isReuseAddress = (Boolean)value;
} else {
Net.setSocketOption(fd, Net.UNSPEC, name, value);
}
return this;
} finally {
end();
}
}
示例12: getOption
import java.net.StandardSocketOptions; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public final <T> T getOption(SocketOption<T> name) throws IOException {
if (name == null)
throw new NullPointerException();
if (!supportedOptions().contains(name))
throw new UnsupportedOperationException("'" + name + "' not supported");
try {
begin();
if (name == StandardSocketOptions.SO_REUSEADDR &&
Net.useExclusiveBind())
{
// SO_REUSEADDR emulated when using exclusive bind
return (T)Boolean.valueOf(isReuseAddress);
}
return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
} finally {
end();
}
}
示例13: setOption
import java.net.StandardSocketOptions; //导入依赖的package包/类
@Override
public final <T> AsynchronousSocketChannel setOption(SocketOption<T> name, T value)
throws IOException
{
if (name == null)
throw new NullPointerException();
if (!supportedOptions().contains(name))
throw new UnsupportedOperationException("'" + name + "' not supported");
try {
begin();
if (writeShutdown)
throw new IOException("Connection has been shutdown for writing");
if (name == StandardSocketOptions.SO_REUSEADDR &&
Net.useExclusiveBind())
{
// SO_REUSEADDR emulated when using exclusive bind
isReuseAddress = (Boolean)value;
} else {
Net.setSocketOption(fd, Net.UNSPEC, name, value);
}
return this;
} finally {
end();
}
}
示例14: options
import java.net.StandardSocketOptions; //导入依赖的package包/类
private static Map<RegistryKey,OptionKey> options() {
Map<RegistryKey,OptionKey> map =
new HashMap<RegistryKey,OptionKey>();
map.put(new RegistryKey(StandardSocketOptions.SO_BROADCAST, Net.UNSPEC), new OptionKey(SocketOptionLevel.Socket, SocketOptionName.Broadcast));
map.put(new RegistryKey(StandardSocketOptions.SO_KEEPALIVE, Net.UNSPEC), new OptionKey(SocketOptionLevel.Socket, SocketOptionName.KeepAlive));
map.put(new RegistryKey(StandardSocketOptions.SO_LINGER, Net.UNSPEC), new OptionKey(SocketOptionLevel.Socket, SocketOptionName.Linger));
map.put(new RegistryKey(StandardSocketOptions.SO_SNDBUF, Net.UNSPEC), new OptionKey(SocketOptionLevel.Socket, SocketOptionName.SendBuffer));
map.put(new RegistryKey(StandardSocketOptions.SO_RCVBUF, Net.UNSPEC), new OptionKey(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer));
map.put(new RegistryKey(StandardSocketOptions.SO_REUSEADDR, Net.UNSPEC), new OptionKey(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress));
map.put(new RegistryKey(StandardSocketOptions.TCP_NODELAY, Net.UNSPEC), new OptionKey(SocketOptionLevel.Tcp, SocketOptionName.NoDelay));
map.put(new RegistryKey(StandardSocketOptions.IP_TOS, StandardProtocolFamily.INET), new OptionKey(SocketOptionLevel.IP, SocketOptionName.TypeOfService));
map.put(new RegistryKey(StandardSocketOptions.IP_MULTICAST_IF, StandardProtocolFamily.INET), new OptionKey(SocketOptionLevel.IP, SocketOptionName.MulticastInterface));
map.put(new RegistryKey(StandardSocketOptions.IP_MULTICAST_TTL, StandardProtocolFamily.INET), new OptionKey(SocketOptionLevel.IP, SocketOptionName.IpTimeToLive));
map.put(new RegistryKey(StandardSocketOptions.IP_MULTICAST_LOOP, StandardProtocolFamily.INET), new OptionKey(SocketOptionLevel.IP, SocketOptionName.MulticastLoopback));
map.put(new RegistryKey(StandardSocketOptions.IP_TOS, StandardProtocolFamily.INET6), new OptionKey(SocketOptionLevel.IPv6, ikvm.internal.Winsock.IPV6_TCLASS));
map.put(new RegistryKey(StandardSocketOptions.IP_MULTICAST_IF, StandardProtocolFamily.INET6), new OptionKey(SocketOptionLevel.IPv6, SocketOptionName.MulticastInterface));
map.put(new RegistryKey(StandardSocketOptions.IP_MULTICAST_TTL, StandardProtocolFamily.INET6), new OptionKey(SocketOptionLevel.IPv6, SocketOptionName.IpTimeToLive));
map.put(new RegistryKey(StandardSocketOptions.IP_MULTICAST_LOOP, StandardProtocolFamily.INET6), new OptionKey(SocketOptionLevel.IPv6, SocketOptionName.MulticastLoopback));
map.put(new RegistryKey(ExtendedSocketOption.SO_OOBINLINE, Net.UNSPEC), new OptionKey(SocketOptionLevel.Socket, SocketOptionName.OutOfBandInline));
return map;
}
示例15: setSocketParams
import java.net.StandardSocketOptions; //导入依赖的package包/类
public void setSocketParams(Connection con, boolean isFrontChannel) throws IOException {
int sorcvbuf = 0;
int sosndbuf = 0;
int soNoDelay = 0;
if (isFrontChannel) {
sorcvbuf = netConfig.getFrontsocketsorcvbuf();
sosndbuf = netConfig.getFrontsocketsosndbuf();
soNoDelay = netConfig.getFrontSocketNoDelay();
} else {
sorcvbuf = netConfig.getBacksocketsorcvbuf();
sosndbuf = netConfig.getBacksocketsosndbuf();
soNoDelay = netConfig.getBackSocketNoDelay();
}
NetworkChannel channel = con.getChannel();
channel.setOption(StandardSocketOptions.SO_RCVBUF, sorcvbuf);
channel.setOption(StandardSocketOptions.SO_SNDBUF, sosndbuf);
channel.setOption(StandardSocketOptions.TCP_NODELAY, soNoDelay == 1);
channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
channel.setOption(StandardSocketOptions.SO_KEEPALIVE, true);
}