use of java.net.MulticastSocket in project jcollectd by collectd.
the class MulticastReceiverTest method createSocket.
@Override
protected DatagramSocket createSocket() throws IOException {
MulticastSocket socket = new MulticastSocket(Network.DEFAULT_PORT + 100);
String laddr = Network.DEFAULT_V4_ADDR;
getReceiver().setListenAddress(laddr);
socket.joinGroup(InetAddress.getByName(laddr));
return socket;
}
use of java.net.MulticastSocket in project openhab1-addons by openhab.
the class SsdpDiscovery method sendDiscoveryBroacast.
/**
* 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;
}
use of java.net.MulticastSocket in project openhab1-addons by openhab.
the class SsdpDiscovery method findIpForResponseKeywords.
/**
* Determines the IP address of a service provided in the network. The
* service is detected by one or more keywords that have to appear in the
* answer message of the service to the SSDP discover broadcast. The
* keywords are not case sensitive. The timeout of the discovery is 120
* seconds.
*
* @param keywords
* The keywords that have to be found case insensitive in the
* response of the service to be searched.
* @return The IP if a service with the keywords has been found, null
* otherwise.
* @throws IOException
*/
public String findIpForResponseKeywords(String... keywords) throws IOException {
try {
logger.debug("Sending SSDP discover.");
MulticastSocket socket = sendDiscoveryBroacast();
logger.debug("Waiting for response.");
return scanResposesForKeywords(socket, keywords);
} catch (SocketTimeoutException e) {
logger.debug("Timeout of request...");
}
return null;
}
use of java.net.MulticastSocket in project CloudStack-archive by CloudStack-extras.
the class MultiCaster method start.
public void start(String strOutboundAddress, String strClusterAddress, int nPort) throws SocketException {
assert (socket == null);
InetAddress addr = null;
try {
addr = InetAddress.getByName(strClusterAddress);
} catch (IOException e) {
s_logger.error("Unexpected exception ", e);
}
if (addr != null && addr.isMulticastAddress()) {
try {
socket = new MulticastSocket(nPort);
socket.setReuseAddress(true);
if (s_logger.isInfoEnabled())
s_logger.info("Join multicast group : " + addr);
((MulticastSocket) socket).joinGroup(addr);
((MulticastSocket) socket).setTimeToLive(1);
if (strOutboundAddress != null) {
if (s_logger.isInfoEnabled())
s_logger.info("set outgoing interface to : " + strOutboundAddress);
InetAddress ia = InetAddress.getByName(strOutboundAddress);
NetworkInterface ni = NetworkInterface.getByInetAddress(ia);
((MulticastSocket) socket).setNetworkInterface(ni);
}
} catch (IOException e) {
s_logger.error("Unexpected exception ", e);
}
} else {
socket = new DatagramSocket(nPort);
socket.setReuseAddress(true);
}
driver = new Thread(this, "Multi-caster");
driver.setDaemon(true);
driver.start();
}
use of java.net.MulticastSocket in project hadoop by apache.
the class TestGangliaSink method testShouldCreateMulticastSocket.
@Test
public void testShouldCreateMulticastSocket() throws Exception {
SubsetConfiguration conf = new ConfigBuilder().add("test.sink.ganglia.multicast", true).subset("test.sink.ganglia");
GangliaSink30 gangliaSink = new GangliaSink30();
gangliaSink.init(conf);
DatagramSocket socket = gangliaSink.getDatagramSocket();
assertTrue("Did not create MulticastSocket", socket != null && socket instanceof MulticastSocket);
int ttl = ((MulticastSocket) socket).getTimeToLive();
assertEquals("Did not set default TTL", 1, ttl);
}
Aggregations