@Override public DatagramChannelConfig setTimeToLive(int ttl) { if (javaSocket instanceof MulticastSocket) { try { ((MulticastSocket) javaSocket).setTimeToLive(ttl); } catch (IOException e) { throw new ChannelException(e); } } else { throw new UnsupportedOperationException(); } return this; }
@Override public DatagramChannelConfig setTimeToLive(int ttl) { if (javaSocket instanceof MulticastSocket) { try { ((MulticastSocket) javaSocket).setTimeToLive(ttl); } catch (IOException e) { throw new ChannelException(e); } } else { throw new UnsupportedOperationException(); } return this; }
protected void setTimeToLive(int ttl, MulticastSocket s) { try { if(s != null) s.setTimeToLive(ttl); } catch(Throwable ex) { // just in case Windows throws an exception (DualStack impl, not implemented) log.error("failed setting ip_ttl to %d: %s", ttl, ex); } }
@Override public DatagramChannelConfig setTimeToLive(int ttl) { if (javaSocket instanceof MulticastSocket) { try { ((MulticastSocket) javaSocket).setTimeToLive(ttl); } catch (IOException e) { throw new ChannelException(e); } } else { throw new UnsupportedOperationException(); } return this; }
public void setTimeToLive(int ttl) { if (socket instanceof MulticastSocket) { try { ((MulticastSocket) socket).setTimeToLive(ttl); } catch (IOException e) { throw new ChannelException(e); } } else { throw new UnsupportedOperationException(); } }
MessageHandler(InetAddress bind_interface) throws Exception { mcast_sock = new MulticastSocket(mcast_port); mcast_sock.setInterface(bind_interface); mcast_sock.setTimeToLive(ttl); mcast_sock.joinGroup(mcast_addr); sock = new DatagramSocket(0, bind_interface); local_addr = sock.getLocalAddress(); local_port = sock.getLocalPort(); }
protected void sendRequest(InetAddress addr, InetAddress bind_addr, int port, int ttl, List<String> query, String passcode) throws Exception { if(mcast_sock == null) { mcast_sock=new MulticastSocket(); mcast_sock.setTimeToLive(ttl); if(bind_addr != null) mcast_sock.setInterface(bind_addr); } StringBuilder request=new StringBuilder(); byte[] authenticationDigest = null; if(passcode != null){ long t1 = (new Date()).getTime(); double q1 = Math.random(); authenticationDigest = Util.createAuthenticationDigest(passcode, t1, q1); } for(int i=0; i < query.size(); i++) { request.append(query.get(i)).append(" "); } byte[] queryPayload = request.toString().getBytes(); byte[] payload = queryPayload; if (authenticationDigest != null) { payload = new byte[authenticationDigest.length + queryPayload.length]; System.arraycopy(authenticationDigest, 0, payload, 0, authenticationDigest.length); System.arraycopy(queryPayload, 0, payload, authenticationDigest.length, queryPayload.length); } DatagramPacket probe=new DatagramPacket(payload, 0, payload.length, addr, port); mcast_sock.send(probe); // System.out.printf("-- sending probe request to %s:%d\n", addr, port); }
synchronized public void init(InetAddress bindAddress, Router router, DatagramProcessor datagramProcessor) throws InitializationException { this.router = router; this.datagramProcessor = datagramProcessor; try { // TODO: UPNP VIOLATION: The spec does not prohibit using the 1900 port here again, however, the // Netgear ReadyNAS miniDLNA implementation will no longer answer if it has to send search response // back via UDP unicast to port 1900... so we use an ephemeral port log.info("Creating bound socket (for datagram input/output) on: " + bindAddress); localAddress = new InetSocketAddress(bindAddress, 0); socket = new MulticastSocket(localAddress); socket.setTimeToLive(configuration.getTimeToLive()); socket.setReceiveBufferSize(262144); // Keep a backlog of incoming datagrams if we are not fast enough } catch (Exception ex) { throw new InitializationException("Could not initialize " + getClass().getSimpleName() + ": " + ex); } }
protected DatagramSocket createSocket() throws IOException { MulticastSocket s = new MulticastSocket(); s.setSendBufferSize(maxTraceDatagramSize); s.setBroadcast(broadcast); s.setLoopbackMode(true); s.setTimeToLive(timeToLive); return s; }
public void start() throws IOException { // https://jira.jboss.org/jira/browse/JGRP-777 - this doesn't work on MacOS, and we don't have // cross talking on Windows anyway, so we just do it for Linux. (How about Solaris ?) // if(can_bind_to_mcast_addr) // diag_sock=Util.createMulticastSocket(getSocketFactory(), // Global.TP_DIAG_MCAST_SOCK, diagnostics_addr, diagnostics_port, log); //else diag_sock=socket_factory.createMulticastSocket("jgroups.tp.diag.mcast_sock", diagnostics_port); diag_sock.setTimeToLive(ttl); List<NetworkInterface> interfaces=bind_interfaces != null? bind_interfaces : Util.getAllAvailableInterfaces(); bindToInterfaces(interfaces, diag_sock); if(thread == null || !thread.isAlive()) { thread=thread_factory.newThread(this, THREAD_NAME); thread.setDaemon(true); thread.start(); } }
/** * Sends the given {@code packet} on this socket, using the given {@code ttl}. This method is * deprecated because it modifies the TTL socket option for this socket twice on each call. * * @throws IOException if an error occurs. * @deprecated Use {@link #setTimeToLive} instead. */ @Deprecated public void send(DatagramPacket packet, byte ttl) throws IOException { checkOpen(); InetAddress packAddr = packet.getAddress(); int currTTL = getTimeToLive(); if (packAddr.isMulticastAddress() && (byte) currTTL != ttl) { try { setTimeToLive(ttl & 0xff); impl.send(packet); } finally { setTimeToLive(currTTL); } } else { impl.send(packet); } }
/** * Creates multicast socket and joins multicast group. * * @throws IOException If fails to create socket or join multicast group. * @return Multicast socket. */ private MulticastSocket createSocket() throws IOException { MulticastSocket sock = new MulticastSocket(mcastPort); sock.setLoopbackMode(false); // Use 'false' to enable support for more than one node on the same machine. if (sockItf != null) sock.setInterface(sockItf); if (sock.getLoopbackMode()) U.warn(log, "Loopback mode is disabled which prevents nodes on the same machine from discovering " + "each other."); sock.joinGroup(mcastGrp); if (ttl != -1) sock.setTimeToLive(ttl); return sock; }
for(int i=0; i < v.size(); i++) { sock=new MulticastSocket(port); sock.setTimeToLive(ttl); sock.setInterface(v.get(i)); sockets[i]=sock;
mcast = new MulticastSocket(myPort); mcast.setLoopbackMode(loopBackMode); mcast.setTimeToLive(getTimeToLive()); if (mcJoinNetworkInterface != null) { mcast.joinGroup(sockAddress, NetworkInterface.getByName(mcJoinNetworkInterface));
mcast_sock=getSocketFactory().createMulticastSocket("jgroups.mping.mcast_sock", mcast_port); mcast_sock.setTimeToLive(ip_ttl); mcast_send_sockets[index]=new MulticastSocket(); mcast_send_sockets[index].setNetworkInterface(intf); mcast_send_sockets[index].setTimeToLive(ip_ttl); index++;
protected CommandChannel createCommandChannel() throws IOException { socket = new MulticastSocket(mcastPort); socket.setLoopbackMode(loopBackMode); socket.setTimeToLive(timeToLive); LOG.debug("Joining multicast address: " + getMulticastAddress()); socket.joinGroup(getMulticastAddress()); socket.setSoTimeout((int)keepAliveInterval); return new CommandDatagramSocket(this, getWireFormat(), getDatagramSize(), getTargetAddress(), createDatagramHeaderMarshaller(), getSocket()); }
CLOUD_MULTICAST_SOCKET = new MulticastSocket(); CLOUD_MULTICAST_SOCKET.setTimeToLive(2); CLOUD_MULTICAST_SOCKET.setNetworkInterface(H2O.CLOUD_MULTICAST_IF);
LOG.info("Enabling multicast for Ganglia with TTL " + multicastTtl); datagramSocket = new MulticastSocket(); ((MulticastSocket) datagramSocket).setTimeToLive(multicastTtl); } else { datagramSocket = new DatagramSocket();
sock.setTimeToLive(ttl);
socket = new MulticastSocket(port); socket.setTimeToLive(config.getTtl().getTtl());