Java Code Examples for java.net.MulticastSocket#setBroadcast()
The following examples show how to use
java.net.MulticastSocket#setBroadcast() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OioDatagramChannel.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
/** * Create a new instance from the given {@link MulticastSocket}. * * @param socket the {@link MulticastSocket} which is used by this instance */ public OioDatagramChannel(MulticastSocket socket) { super(null); boolean success = false; try { socket.setSoTimeout(SO_TIMEOUT); socket.setBroadcast(false); success = true; } catch (SocketException e) { throw new ChannelException( "Failed to configure the datagram socket timeout.", e); } finally { if (!success) { socket.close(); } } this.socket = socket; config = new DefaultOioDatagramChannelConfig(this, socket); }
Example 2
Source File: OioDatagramChannel.java From netty4.0.27Learn with Apache License 2.0 | 6 votes |
/** * Create a new instance from the given {@link MulticastSocket}. * * @param socket the {@link MulticastSocket} which is used by this instance */ public OioDatagramChannel(MulticastSocket socket) { super(null); boolean success = false; try { socket.setSoTimeout(SO_TIMEOUT); socket.setBroadcast(false); success = true; } catch (SocketException e) { throw new ChannelException( "Failed to configure the datagram socket timeout.", e); } finally { if (!success) { socket.close(); } } this.socket = socket; config = new DefaultDatagramChannelConfig(this, socket); }
Example 3
Source File: CcuDiscoveryService.java From smarthome with Eclipse Public License 2.0 | 6 votes |
private synchronized void startDiscovery() { try { logger.debug("Starting Homematic CCU discovery scan"); String configuredBroadcastAddress = networkAddressService.getConfiguredBroadcastAddress(); if (configuredBroadcastAddress != null) { broadcastAddress = InetAddress.getByName(configuredBroadcastAddress); } if (broadcastAddress == null) { logger.warn("Homematic CCU discovery: discovery not possible, no broadcast address found"); return; } socket = new MulticastSocket(); socket.setBroadcast(true); socket.setTimeToLive(5); socket.setSoTimeout(800); sendBroadcast(); receiveResponses(); } catch (Exception ex) { logger.error("An error was thrown while running Homematic CCU discovery {}", ex.getMessage(), ex); } finally { scanFuture = null; } }
Example 4
Source File: SsdpDiscovery.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
private static MulticastSocket setUpSocket() throws IOException { MulticastSocket recSocket = new MulticastSocket(null); recSocket.bind(new InetSocketAddress(InetAddress.getByName("0.0.0.0"), PORT)); recSocket.setTimeToLive(10); recSocket.setSoTimeout(1000); recSocket.setBroadcast(true); return recSocket; }