use of java.net.MulticastSocket in project JAirPort by froks.
the class JmDNSImpl method send.
/**
* Send an outgoing multicast DNS message.
*
* @param out
* @exception IOException
*/
public void send(DNSOutgoing out) throws IOException {
if (!out.isEmpty()) {
byte[] message = out.data();
final DatagramPacket packet = new DatagramPacket(message, message.length, _group, DNSConstants.MDNS_PORT);
if (logger.isLoggable(Level.FINEST)) {
try {
final DNSIncoming msg = new DNSIncoming(packet);
if (logger.isLoggable(Level.FINEST)) {
logger.finest("send(" + this.getName() + ") JmDNS out:" + msg.print(true));
}
} catch (final IOException e) {
logger.throwing(getClass().toString(), "send(" + this.getName() + ") - JmDNS can not parse what it sends!!!", e);
}
}
final MulticastSocket ms = _socket;
if (ms != null && !ms.isClosed()) {
ms.send(packet);
}
}
}
use of java.net.MulticastSocket in project hazelcast by hazelcast.
the class MulticastDiscoveryStrategy method initializeMulticastSocket.
private void initializeMulticastSocket() {
try {
int port = getOrDefault(MulticastProperties.PORT, DEFAULT_MULTICAST_PORT);
PortValueValidator validator = new PortValueValidator();
validator.validate(port);
String group = getOrDefault(MulticastProperties.GROUP, DEFAULT_MULTICAST_GROUP);
multicastSocket = new MulticastSocket(null);
multicastSocket.bind(new InetSocketAddress(port));
multicastSocket.setReuseAddress(true);
multicastSocket.setTimeToLive(SOCKET_TIME_TO_LIVE);
multicastSocket.setReceiveBufferSize(DATA_OUTPUT_BUFFER_SIZE);
multicastSocket.setSendBufferSize(DATA_OUTPUT_BUFFER_SIZE);
multicastSocket.setSoTimeout(SOCKET_TIMEOUT);
multicastSocket.joinGroup(InetAddress.getByName(group));
multicastDiscoverySender = new MulticastDiscoverySender(discoveryNode, multicastSocket, logger, group, port);
multicastDiscoveryReceiver = new MulticastDiscoveryReceiver(multicastSocket, logger);
if (discoveryNode != null) {
isClient = false;
}
} catch (Exception e) {
logger.finest(e.getMessage());
rethrow(e);
}
}
use of java.net.MulticastSocket in project tomcat by apache.
the class McastServiceImpl method setupSocket.
protected void setupSocket() throws IOException {
if (mcastBindAddress != null) {
try {
log.info(sm.getString("mcastServiceImpl.bind", address, Integer.toString(port)));
socket = new MulticastSocket(new InetSocketAddress(address, port));
} catch (BindException e) {
/*
* On some platforms (e.g. Linux) it is not possible to bind
* to the multicast address. In this case only bind to the
* port.
*/
log.info(sm.getString("mcastServiceImpl.bind.failed"));
socket = new MulticastSocket(port);
}
} else {
socket = new MulticastSocket(port);
}
//hint if we want disable loop back(local machine) messages
socket.setLoopbackMode(localLoopbackDisabled);
if (mcastBindAddress != null) {
if (log.isInfoEnabled())
log.info(sm.getString("mcastServiceImpl.setInterface", mcastBindAddress));
socket.setInterface(mcastBindAddress);
}
//force a so timeout so that we don't block forever
if (mcastSoTimeout <= 0)
mcastSoTimeout = (int) sendFrequency;
if (log.isInfoEnabled()) {
log.info(sm.getString("mcastServiceImpl.setSoTimeout", Integer.toString(mcastSoTimeout)));
}
socket.setSoTimeout(mcastSoTimeout);
if (mcastTTL >= 0) {
if (log.isInfoEnabled())
log.info(sm.getString("mcastServiceImpl.setTTL", Integer.toString(mcastTTL)));
socket.setTimeToLive(mcastTTL);
}
}
use of java.net.MulticastSocket in project jcollectd by collectd.
the class MBeanReceiver method setup.
private void setup() throws Exception {
DatagramSocket socket = getSocket();
if (socket instanceof MulticastSocket) {
MulticastSocket mcast = (MulticastSocket) socket;
System.err.println("Multicast interface=" + mcast.getInterface());
}
System.err.println(getListenAddress() + ":" + getPort() + " listening...");
listen();
}
use of java.net.MulticastSocket in project jcollectd by collectd.
the class UdpSender method getMulticastSocket.
private MulticastSocket getMulticastSocket() throws IOException {
if (_mcast == null) {
_mcast = new MulticastSocket();
_mcast.setTimeToLive(1);
}
return _mcast;
}
Aggregations