DatagramSocket socket = new DatagramSocket(PORT); socket.setBroadcast(true); DatagramPacket packet = new DatagramPacket(data.getBytes(), data.length(), getBroadcastAddress(), DISCOVERY_PORT); socket.send(packet); byte[] buf = new byte[1024]; DatagramPacket packet = new DatagramPacket(buf, buf.length); socket.receive(packet);
protected DatagramSocket createSocket() throws IOException { DatagramSocket s = new DatagramSocket(); s.setSendBufferSize(maxTraceDatagramSize); s.setBroadcast(broadcast); return s; }
public void setBroadcast(boolean broadcast) { try { socket.setBroadcast(broadcast); } catch (SocketException e) { throw new ChannelException(e); } }
DatagramPacket dp; dp = new DatagramPacket(Message.getBytes(), Message.length(), Main.BroadcastAddress, Main.SERVER_PORT); ds.setBroadcast(true); ds.send(dp);
public void start() throws Exception { for(int i=bind_port; i <= bind_port+port_range; i++) { try { sock=getSocketFactory().createDatagramSocket("jgroups.bping.sock", i); break; } catch(Throwable t) { if(i > bind_port+port_range) throw new RuntimeException("failed to open a port in range [" + bind_port + " - " + (bind_port+port_range) + "]", t); } } if (null == sock) throw new RuntimeException("failed to open a port in range [" + bind_port + " - " + (bind_port+port_range) + "]"); sock.setBroadcast(true); startReceiver(); super.start(); }
@Override public DatagramChannelConfig setBroadcast(boolean broadcast) { try { // See: https://github.com/netty/netty/issues/576 if (broadcast && !javaSocket.getLocalAddress().isAnyLocalAddress() && !PlatformDependent.isWindows() && !PlatformDependent.maybeSuperUser()) { // Warn a user about the fact that a non-root user can't receive a // broadcast packet on *nix if the socket is bound on non-wildcard address. logger.warn( "A non-root user can't receive a broadcast packet if the socket " + "is not bound to a wildcard address; setting the SO_BROADCAST flag " + "anyway as requested on the socket which is bound to " + javaSocket.getLocalSocketAddress() + '.'); } javaSocket.setBroadcast(broadcast); } catch (SocketException e) { throw new ChannelException(e); } return this; }
@Override public DatagramChannelConfig setBroadcast(boolean broadcast) { try { // See: https://github.com/netty/netty/issues/576 if (broadcast && !javaSocket.getLocalAddress().isAnyLocalAddress() && !PlatformDependent.isWindows() && !PlatformDependent.maybeSuperUser()) { // Warn a user about the fact that a non-root user can't receive a // broadcast packet on *nix if the socket is bound on non-wildcard address. logger.warn( "A non-root user can't receive a broadcast packet if the socket " + "is not bound to a wildcard address; setting the SO_BROADCAST flag " + "anyway as requested on the socket which is bound to " + javaSocket.getLocalSocketAddress() + '.'); } javaSocket.setBroadcast(broadcast); } catch (SocketException e) { throw new ChannelException(e); } return this; }
} else if (option == Options.BROADCAST) { old = Boolean.valueOf(socket.getBroadcast()); socket.setBroadcast(Options.BROADCAST.cast(value, Boolean.FALSE).booleanValue()); } else if (option == Options.MULTICAST_TTL) { old = option.cast(channel.getOption(StandardSocketOptions.IP_MULTICAST_TTL));
@Override public DatagramChannelConfig setBroadcast(boolean broadcast) { try { // See: https://github.com/netty/netty/issues/576 if (broadcast && !javaSocket.getLocalAddress().isAnyLocalAddress() && !PlatformDependent.isWindows() && !PlatformDependent.maybeSuperUser()) { // Warn a user about the fact that a non-root user can't receive a // broadcast packet on *nix if the socket is bound on non-wildcard address. logger.warn( "A non-root user can't receive a broadcast packet if the socket " + "is not bound to a wildcard address; setting the SO_BROADCAST flag " + "anyway as requested on the socket which is bound to " + javaSocket.getLocalSocketAddress() + '.'); } javaSocket.setBroadcast(broadcast); } catch (SocketException e) { throw new ChannelException(e); } return this; }
/** {@inheritDoc} */ public MulticastMessageChannel createUdpServer(final InetSocketAddress bindAddress, final ChannelListener<? super MulticastMessageChannel> bindListener, final OptionMap optionMap) throws IOException { checkShutdown(); final DatagramChannel channel; if (bindAddress != null) { InetAddress address = bindAddress.getAddress(); if (address instanceof Inet6Address) { channel = DatagramChannel.open(StandardProtocolFamily.INET6); } else { channel = DatagramChannel.open(StandardProtocolFamily.INET); } } else { channel = DatagramChannel.open(); } channel.configureBlocking(false); if (optionMap.contains(Options.BROADCAST)) channel.socket().setBroadcast(optionMap.get(Options.BROADCAST, false)); if (optionMap.contains(Options.IP_TRAFFIC_CLASS)) channel.socket().setTrafficClass(optionMap.get(Options.IP_TRAFFIC_CLASS, -1)); if (optionMap.contains(Options.RECEIVE_BUFFER)) channel.socket().setReceiveBufferSize(optionMap.get(Options.RECEIVE_BUFFER, -1)); channel.socket().setReuseAddress(optionMap.get(Options.REUSE_ADDRESSES, true)); if (optionMap.contains(Options.SEND_BUFFER)) channel.socket().setSendBufferSize(optionMap.get(Options.SEND_BUFFER, -1)); channel.socket().bind(bindAddress); final NioUdpChannel udpChannel = new NioUdpChannel(this, channel); ChannelListeners.invokeChannelListener(udpChannel, bindListener); return udpChannel; }
DatagramSocket socket = new DatagramSocket(PORT); socket.setBroadcast(true); DatagramPacket packet = new DatagramPacket(data.getBytes(), data.length(), getBroadcastAddress(), PORT); socket.send(packet); // If you want to listen for a response ... byte[] buf = new byte[1024]; DatagramPacket packet = new DatagramPacket(buf, buf.length); socket.receive(packet);
@Override public void run() { while (_running) { try { DatagramSocket dhcpSocket = new DatagramSocket(dhcpServerPort, InetAddress.getByAddress(new byte[] {0, 0, 0, 0})); dhcpSocket.setBroadcast(true); while (true) { byte[] buf = new byte[bufferSize]; DatagramPacket dgp = new DatagramPacket(buf, buf.length); dhcpSocket.receive(dgp); // _executor.execute(new DhcpPacketParser(buf)); } } catch (IOException e) { s_logger.debug(e.getMessage()); } } } }
public UdpProgressParser(ProgressListener listener, int port, InetAddress addr) throws SocketException, URISyntaxException { super(listener); this.socket = new DatagramSocket(port, checkNotNull(addr)); this.address = createUri("udp", socket.getLocalAddress(), socket.getLocalPort()); this.socket.setBroadcast(false); // this.socket.setSoTimeout(); // TODO Setup timeouts }
protected DatagramSocket createSocket() throws IOException { DatagramSocket s = new DatagramSocket(); s.setSendBufferSize(maxTraceDatagramSize); s.setBroadcast(broadcast); return s; }
protected DatagramSocket createSocket() throws IOException { DatagramSocket s = new DatagramSocket(); s.setSendBufferSize(maxTraceDatagramSize); s.setBroadcast(broadcast); return s; }
protected DatagramSocket createSocket() throws IOException { DatagramSocket s = new DatagramSocket(); s.setSendBufferSize(maxTraceDatagramSize); s.setBroadcast(broadcast); return s; }
@Override public void setBroadcast(boolean broadcast) { try { channel.socket().setBroadcast(broadcast); } catch (SocketException e) { throw new RuntimeIoException(e); } }
@Override public void setBroadcast(boolean broadcast) { try { ch.socket().setBroadcast(broadcast); } catch (SocketException e) { throw new RuntimeIOException(e); } }
@Override public void setBroadcast(boolean broadcast) { try { channel.socket().setBroadcast(broadcast); } catch (SocketException e) { throw new RuntimeIoException(e); } }