@Override public NetworkInterface getNetworkInterface() { if (DetectionUtil.javaVersion() < 7) { throw new UnsupportedOperationException(); } else { try { return channel.getOption(StandardSocketOptions.IP_MULTICAST_IF); } catch (IOException e) { throw new ChannelException(e); } } }
@Override public boolean isLoopbackModeDisabled() { if (DetectionUtil.javaVersion() < 7) { throw new UnsupportedOperationException(); } else { try { return channel.getOption(StandardSocketOptions.IP_MULTICAST_LOOP); } catch (IOException e) { throw new ChannelException(e); } } }
@Override public int getTimeToLive() { if (DetectionUtil.javaVersion() < 7) { throw new UnsupportedOperationException(); } else { try { return channel.getOption(StandardSocketOptions.IP_MULTICAST_TTL); } catch (IOException e) { throw new ChannelException(e); } } }
@Override public void open() throws IOException { if (channel == null) { channel = DatagramChannel.open(); if (maxSendBufferSize > 0) { channel.setOption(StandardSocketOptions.SO_SNDBUF, maxSendBufferSize); final int actualSendBufSize = channel.getOption(StandardSocketOptions.SO_SNDBUF); if (actualSendBufSize < maxSendBufferSize) { logger.warn("Attempted to set Socket Send Buffer Size to " + maxSendBufferSize + " bytes but could only set to " + actualSendBufSize + "bytes. You may want to " + "consider changing the Operating System's maximum receive buffer"); } } } if (!channel.isConnected()) { channel.connect(new InetSocketAddress(InetAddress.getByName(host), port)); } }
private DatagramChannel createAndBindDatagramChannel(final InetAddress nicIPAddress, final int port, final int receiveBufferSize) throws IOException { final DatagramChannel dChannel = DatagramChannel.open(); dChannel.configureBlocking(false); if (receiveBufferSize > 0) { dChannel.setOption(StandardSocketOptions.SO_RCVBUF, receiveBufferSize); final int actualReceiveBufSize = dChannel.getOption(StandardSocketOptions.SO_RCVBUF); if (actualReceiveBufSize < receiveBufferSize) { LOGGER.warn(this + " attempted to set UDP Receive Buffer Size to " + receiveBufferSize + " bytes but could only set to " + actualReceiveBufSize + "bytes. You may want to consider changing the Operating System's " + "maximum receive buffer"); } } dChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true); dChannel.bind(new InetSocketAddress(nicIPAddress, port)); return dChannel; }
public <T> T getOption(final Option<T> option) throws UnsupportedOptionException, IOException { final DatagramChannel channel = datagramChannel; final DatagramSocket socket = channel.socket(); if (option == Options.RECEIVE_BUFFER) { return option.cast(Integer.valueOf(socket.getReceiveBufferSize())); } else if (option == Options.SEND_BUFFER) { return option.cast(Integer.valueOf(socket.getSendBufferSize())); } else if (option == Options.BROADCAST) { return option.cast(Boolean.valueOf(socket.getBroadcast())); } else if (option == Options.IP_TRAFFIC_CLASS) { return option.cast(Integer.valueOf(socket.getTrafficClass())); } else if (option == Options.MULTICAST_TTL) { return option.cast(channel.getOption(StandardSocketOptions.IP_MULTICAST_TTL)); } else { return null; } }
@Override public void open(final InetAddress nicAddress, final int port, final int maxBufferSize) throws IOException { stopped = false; datagramChannel = DatagramChannel.open(); datagramChannel.configureBlocking(false); if (maxBufferSize > 0) { datagramChannel.setOption(StandardSocketOptions.SO_RCVBUF, maxBufferSize); final int actualReceiveBufSize = datagramChannel.getOption(StandardSocketOptions.SO_RCVBUF); if (actualReceiveBufSize < maxBufferSize) { logger.warn("Attempted to set Socket Buffer Size to " + maxBufferSize + " bytes but could only set to " + actualReceiveBufSize + "bytes. You may want to consider changing the Operating System's " + "maximum receive buffer"); } } // we don't have to worry about nicAddress being null here because InetSocketAddress already handles it datagramChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true); datagramChannel.socket().bind(new InetSocketAddress(nicAddress, port)); // if a sending host and port were provided then connect to that specific address to only receive // datagrams from that host/port, otherwise we can receive datagrams from any host/port if (sendingHost != null && sendingPort != null) { datagramChannel.connect(new InetSocketAddress(sendingHost, sendingPort)); } selector = Selector.open(); datagramChannel.register(selector, SelectionKey.OP_READ); }
socket.setBroadcast(Options.BROADCAST.cast(value, Boolean.FALSE).booleanValue()); } else if (option == Options.MULTICAST_TTL) { old = option.cast(channel.getOption(StandardSocketOptions.IP_MULTICAST_TTL)); channel.setOption(StandardSocketOptions.IP_MULTICAST_TTL, (Integer) value); } else {
multicastTtl = sendDatagramChannel.getOption(StandardSocketOptions.IP_MULTICAST_TTL);
@Override public <T> T getOption(SocketOption<T> socketOption) throws IOException { return channel.getOption(socketOption); }
@Override public <T> T getOption(SocketOption<T> socketOption) throws IOException { return channel.getOption(socketOption); }
public <T> T getOption(SocketOption<T> name) throws IOException { return delegate.getOption(name); } public Set<SocketOption<?>> supportedOptions() { return delegate.supportedOptions(); }
@Override public boolean isLoopbackModeDisabled() { if (DetectionUtil.javaVersion() < 7) { throw new UnsupportedOperationException(); } else { try { return channel.getOption(StandardSocketOptions.IP_MULTICAST_LOOP); } catch (IOException e) { throw new ChannelException(e); } } }
@Override public NetworkInterface getNetworkInterface() { if (DetectionUtil.javaVersion() < 7) { throw new UnsupportedOperationException(); } else { try { return channel.getOption(StandardSocketOptions.IP_MULTICAST_IF); } catch (IOException e) { throw new ChannelException(e); } } }
@Override public boolean isLoopbackModeDisabled() { if (DetectionUtil.javaVersion() < 7) { throw new UnsupportedOperationException(); } else { try { return channel.getOption(StandardSocketOptions.IP_MULTICAST_LOOP); } catch (IOException e) { throw new ChannelException(e); } } }
@Override public int getTimeToLive() { if (DetectionUtil.javaVersion() < 7) { throw new UnsupportedOperationException(); } else { try { return channel.getOption(StandardSocketOptions.IP_MULTICAST_TTL); } catch (IOException e) { throw new ChannelException(e); } } }
@Override public NetworkInterface getNetworkInterface() { if (DetectionUtil.javaVersion() < 7) { throw new UnsupportedOperationException(); } else { try { return channel.getOption(StandardSocketOptions.IP_MULTICAST_IF); } catch (IOException e) { throw new ChannelException(e); } } }
@Override public int getTimeToLive() { if (DetectionUtil.javaVersion() < 7) { throw new UnsupportedOperationException(); } else { try { return channel.getOption(StandardSocketOptions.IP_MULTICAST_TTL); } catch (IOException e) { throw new ChannelException(e); } } }
public <T> T getOption(final Option<T> option) throws UnsupportedOptionException, IOException { final DatagramChannel channel = datagramChannel; final DatagramSocket socket = channel.socket(); if (option == Options.RECEIVE_BUFFER) { return option.cast(Integer.valueOf(socket.getReceiveBufferSize())); } else if (option == Options.SEND_BUFFER) { return option.cast(Integer.valueOf(socket.getSendBufferSize())); } else if (option == Options.BROADCAST) { return option.cast(Boolean.valueOf(socket.getBroadcast())); } else if (option == Options.IP_TRAFFIC_CLASS) { return option.cast(Integer.valueOf(socket.getTrafficClass())); } else if (option == Options.MULTICAST_TTL) { return option.cast(channel.getOption(StandardSocketOptions.IP_MULTICAST_TTL)); } else { return null; } }