use of java.net.MulticastSocket in project tomee by apache.
the class MulticastPulseAgent method getSockets.
private static MulticastSocket[] getSockets(final InetAddress ia, final int port) throws Exception {
final ArrayList<MulticastSocket> list = new ArrayList<MulticastSocket>();
for (final NetworkInterface ni : getInterfaces()) {
MulticastSocket ms = null;
try {
ms = new MulticastSocket(port);
ms.setNetworkInterface(ni);
ms.setSoTimeout(0);
ms.setTimeToLive(TTL);
if (!ms.getBroadcast()) {
ms.setBroadcast(true);
}
ms.joinGroup(ia);
list.add(ms);
log.debug(String.format("Created MulticastSocket for '%1$s:%2$s' on network adapter: %3$s", ia.getHostName(), port, ni));
} catch (final Throwable e) {
if (null != ms) {
try {
ms.close();
} catch (final Throwable t) {
//Ignore
}
}
}
}
return list.toArray(new MulticastSocket[list.size()]);
}
use of java.net.MulticastSocket in project ha-bridge by bwssytems.
the class SystemControl method pingListener.
protected void pingListener() {
try {
byte[] buf = new byte[256];
String testData = "M-SEARCH * HTTP/1.1\nHOST: " + Configuration.UPNP_MULTICAST_ADDRESS + ":" + Configuration.UPNP_DISCOVERY_PORT + "ST: urn:schemas-upnp-org:device:CloudProxy:1\nMAN: \"ssdp:discover\"\nMX: 3";
buf = testData.getBytes();
MulticastSocket socket = new MulticastSocket(Configuration.UPNP_DISCOVERY_PORT);
InetAddress group = InetAddress.getByName(Configuration.UPNP_MULTICAST_ADDRESS);
DatagramPacket packet;
packet = new DatagramPacket(buf, buf.length, group, Configuration.UPNP_DISCOVERY_PORT);
socket.send(packet);
socket.close();
} catch (IOException e) {
log.warn("Error pinging listener. " + e.getMessage());
}
}
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