Java Code Examples for java.net.MulticastSocket#setReuseAddress()
The following examples show how to use
java.net.MulticastSocket#setReuseAddress() .
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: MulticastReceiverImpl.java From TVRemoteIME with GNU General Public License v2.0 | 6 votes |
synchronized public void init(NetworkInterface networkInterface, Router router, NetworkAddressFactory networkAddressFactory, DatagramProcessor datagramProcessor) throws InitializationException { this.router = router; this.networkAddressFactory = networkAddressFactory; this.datagramProcessor = datagramProcessor; this.multicastInterface = networkInterface; try { log.info("Creating wildcard socket (for receiving multicast datagrams) on port: " + configuration.getPort()); multicastAddress = new InetSocketAddress(configuration.getGroup(), configuration.getPort()); socket = new MulticastSocket(configuration.getPort()); socket.setReuseAddress(true); socket.setReceiveBufferSize(32768); // Keep a backlog of incoming datagrams if we are not fast enough log.info("Joining multicast group: " + multicastAddress + " on network interface: " + multicastInterface.getDisplayName()); socket.joinGroup(multicastAddress, multicastInterface); } catch (Exception ex) { throw new InitializationException("Could not initialize " + getClass().getSimpleName() + ": " + ex); } }
Example 2
Source File: MulticastReceiverImpl.java From DroidDLNA with GNU General Public License v3.0 | 6 votes |
synchronized public void init(NetworkInterface networkInterface, Router router, NetworkAddressFactory networkAddressFactory, DatagramProcessor datagramProcessor) throws InitializationException { this.router = router; this.networkAddressFactory = networkAddressFactory; this.datagramProcessor = datagramProcessor; this.multicastInterface = networkInterface; try { log.info("Creating wildcard socket (for receiving multicast datagrams) on port: " + configuration.getPort()); multicastAddress = new InetSocketAddress(configuration.getGroup(), configuration.getPort()); socket = new MulticastSocket(configuration.getPort()); socket.setReuseAddress(true); socket.setReceiveBufferSize(32768); // Keep a backlog of incoming datagrams if we are not fast enough log.info("Joining multicast group: " + multicastAddress + " on network interface: " + multicastInterface.getDisplayName()); socket.joinGroup(multicastAddress, multicastInterface); } catch (Exception ex) { throw new InitializationException("Could not initialize " + getClass().getSimpleName() + ": " + ex); } }
Example 3
Source File: UDPMulticastReceiver.java From moleculer-java with MIT License | 5 votes |
@Override protected void connect() throws Exception { // Start multicast receiver multicastReceiver = new MulticastSocket(udpPort); multicastReceiver.setReuseAddress(udpReuseAddr); InetAddress inetAddress = InetAddress.getByName(udpAddress); if (netIf == null) { multicastReceiver.joinGroup(inetAddress); } else { InetSocketAddress socketAddress = new InetSocketAddress(inetAddress, udpPort); try { multicastReceiver.joinGroup(socketAddress, netIf); } catch (Exception unsupportedAddress) { disconnect(); return; } } // Start thread super.connect(); // Log String msg = "Multicast discovery service started on udp://" + udpAddress + ':' + udpPort; if (netIf == null) { logger.info(msg + '.'); } else { logger.info(msg + " (" + netIf.getDisplayName() + ")."); } }
Example 4
Source File: UDPTransport.java From mpegts-streamer with Apache License 2.0 | 5 votes |
private UDPTransport(String address, int port, int ttl, int soTimeout) throws IOException { // InetSocketAddress inetSocketAddress = new InetSocketAddress(address, port); // Create the socket but we don't bind it as we are only going to send data // Note that we don't have to join the multicast group if we are only sending data and not receiving multicastSocket = new MulticastSocket(); multicastSocket.setReuseAddress(true); multicastSocket.setSoTimeout(soTimeout); multicastSocket.setTimeToLive(ttl); }
Example 5
Source File: SsdpDiscovery.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
/** * Broadcasts a SSDP discovery message into the network to find provided * services. * * @return The Socket the answers will arrive at. * @throws UnknownHostException * @throws IOException * @throws SocketException * @throws UnsupportedEncodingException */ private MulticastSocket sendDiscoveryBroacast() throws UnknownHostException, IOException, SocketException, UnsupportedEncodingException { InetAddress multicastAddress = InetAddress.getByName("239.255.255.250"); final int port = 1900; MulticastSocket socket = new MulticastSocket(port); socket.setReuseAddress(true); socket.setSoTimeout(130000); socket.joinGroup(multicastAddress); byte[] requestMessage = DISCOVER_MESSAGE.getBytes("UTF-8"); DatagramPacket datagramPacket = new DatagramPacket(requestMessage, requestMessage.length, multicastAddress, port); socket.send(datagramPacket); return socket; }
Example 6
Source File: MulticastEchoServer.java From tutorials with MIT License | 4 votes |
public MulticastEchoServer() throws IOException { socket = new MulticastSocket(4446); socket.setReuseAddress(true); group = InetAddress.getByName("230.0.0.0"); socket.joinGroup(group); }