java.net.MulticastSocket Java Examples
The following examples show how to use
java.net.MulticastSocket.
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: TesterMulticast.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override public void run() { try (MulticastSocket s = new MulticastSocket(PORT)) { s.setLoopbackMode(false); s.joinGroup(INET_ADDRESS); DatagramPacket p = new DatagramPacket(new byte[4], 4); p.setAddress(INET_ADDRESS); p.setPort(PORT); long counter = 0; String msg; while (run) { msg = String.format("%04d", Long.valueOf(counter)); p.setData(msg.getBytes()); System.out.println("Tx: " + msg); s.send(p); counter++; Thread.sleep(500); } } catch (Exception e) { e.printStackTrace(); } }
Example #2
Source File: DatagramIOImpl.java From DroidDLNA with GNU General Public License v3.0 | 6 votes |
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); } }
Example #3
Source File: PlainMulticastSender.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
public void sendFrame(final Frame frame) throws IOException { final byte[] message = toValidMessage(frame); final DatagramPacket packet = new DatagramPacket(message, 0, message.length, mcastAddress, mcastPort); for (final MulticastSocket mcastSocket : mcastSockets) { try { sentMessages++; mcastSocket.send(packet); } catch (final IOException e) { final String exceptionMessage = e.getMessage(); if (exceptionMessage.endsWith(NO_BUFFER_SPACE_AVAILABLE) || exceptionMessage.endsWith(NO_ROUTE_TO_HOST)) { final NetworkInterface networkInterface = mcastSocket.getNetworkInterface(); final InetAddress mcastSocketInterface = mcastSocket.getInterface(); LOG.warn(createIgnoredWarning(exceptionMessage, networkInterface, mcastSocketInterface)); } else { throw e; } } } }
Example #4
Source File: UDPDiscoverySender.java From commons-jcs with Apache License 2.0 | 6 votes |
/** * Constructor for the UDPDiscoverySender object * <p> * This sender can be used to send multiple messages. * <p> * When you are done sending, you should destroy the socket sender. * <p> * @param host * @param port * @param udpTTL the Datagram packet time-to-live * @throws IOException */ public UDPDiscoverySender( String host, int port, int udpTTL ) throws IOException { try { log.debug( "Constructing socket for sender on port [{0}]", port ); localSocket = new MulticastSocket( port ); if (udpTTL > 0) { log.debug( "Setting datagram TTL to [{0}]", udpTTL ); localSocket.setTimeToLive(udpTTL); } // Remote address. multicastAddress = InetAddress.getByName( host ); } catch ( IOException e ) { log.error( "Could not bind to multicast address [{0}]", host, e ); throw e; } this.multicastPort = port; }
Example #5
Source File: MulticastDiscoveryAgent.java From qpid-jms with Apache License 2.0 | 6 votes |
public static void trySetNetworkInterface(MulticastSocket mcastSock) throws SocketException { List<NetworkInterface> interfaces = findNetworkInterfaces(); SocketException lastError = null; boolean found = false; for (NetworkInterface networkInterface : interfaces) { try { mcastSock.setNetworkInterface(networkInterface); LOG.debug("Configured mcast socket {} to network interface {}", mcastSock, networkInterface); found = true; break; } catch (SocketException error) { lastError = error; } } if (!found) { if (lastError != null) { throw lastError; } else { throw new SocketException("No NetworkInterface available for this socket."); } } }
Example #6
Source File: MultiCastManager.java From openbd-core with GNU General Public License v3.0 | 6 votes |
public RxdThread() { super("MultiCastManager.RxdThread." + address + "#" + port); setDaemon(true); bReceiving = true; try { msocket = new MulticastSocket( port ); msocket.setInterface( bindAddress ); msocket.joinGroup(groupAddr); start(); cfcThread = new cfcRunnerThread(); } catch (IOException e) { log( "RxdThread.IOException:" + e.getMessage() ); } }
Example #7
Source File: DefaultDatagramChannelConfig.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
@Override public DatagramChannelConfig setNetworkInterface(NetworkInterface networkInterface) { if (javaSocket instanceof MulticastSocket) { try { ((MulticastSocket) javaSocket).setNetworkInterface(networkInterface); } catch (SocketException e) { throw new ChannelException(e); } } else { throw new UnsupportedOperationException(); } return this; }
Example #8
Source File: UDP.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
private String dumpSocketInfo() throws Exception { StringBuffer sb=new StringBuffer(128); sb.append("local_addr=").append(local_addr); sb.append(", mcast_addr=").append(mcast_addr); sb.append(", bind_addr=").append(bind_addr); sb.append(", ttl=").append(ip_ttl); if(sock != null) { sb.append("\nsock: bound to "); sb.append(sock.getLocalAddress().getHostAddress()).append(':').append(sock.getLocalPort()); sb.append(", receive buffer size=").append(sock.getReceiveBufferSize()); sb.append(", send buffer size=").append(sock.getSendBufferSize()); } if(mcast_recv_sock != null) { sb.append("\nmcast_recv_sock: bound to "); sb.append(mcast_recv_sock.getInterface().getHostAddress()).append(':').append(mcast_recv_sock.getLocalPort()); sb.append(", send buffer size=").append(mcast_recv_sock.getSendBufferSize()); sb.append(", receive buffer size=").append(mcast_recv_sock.getReceiveBufferSize()); } if(mcast_send_sock != null) { sb.append("\nmcast_send_sock: bound to "); sb.append(mcast_send_sock.getInterface().getHostAddress()).append(':').append(mcast_send_sock.getLocalPort()); sb.append(", send buffer size=").append(mcast_send_sock.getSendBufferSize()); sb.append(", receive buffer size=").append(mcast_send_sock.getReceiveBufferSize()); } if(mcast_send_sockets != null) { sb.append("\n").append(mcast_send_sockets.length).append(" mcast send sockets:\n"); MulticastSocket s; for(int i=0; i < mcast_send_sockets.length; i++) { s=mcast_send_sockets[i]; sb.append(s.getInterface().getHostAddress()).append(':').append(s.getLocalPort()); sb.append(", send buffer size=").append(s.getSendBufferSize()); sb.append(", receive buffer size=").append(s.getReceiveBufferSize()).append("\n"); } } return sb.toString(); }
Example #9
Source File: UDP.java From openvisualtraceroute with GNU Lesser General Public License v3.0 | 5 votes |
private static void test() throws Exception { final String hostname = "google.com"; final String localhost = "localhost"; final MulticastSocket datagramSocket = new MulticastSocket(); datagramSocket.setSoTimeout(10000); short ttl = 1; final InetAddress receiverAddress = InetAddress.getByName(hostname); while (ttl < 100) { try { byte[] buffer = "0123456789".getBytes(); datagramSocket.setTimeToLive(ttl++); final DatagramPacket sendPacket = new DatagramPacket(buffer, buffer.length, receiverAddress, 80); datagramSocket.send(sendPacket); buffer = new byte[10]; final DatagramPacket receivePacket = new DatagramPacket(buffer, buffer.length); datagramSocket.receive(receivePacket); System.out.println("ttl=" + ttl + " address=" + receivePacket.getAddress().getHostAddress() + " data=" + new String(receivePacket.getData())); Thread.sleep(1000); } catch (final SocketTimeoutException e) { System.out.println("timeout ttl=" + ttl); } } }
Example #10
Source File: SetGetNetworkInterfaceTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { boolean passed = true; try { MulticastSocket ms = new MulticastSocket(); Enumeration<NetworkInterface> networkInterfaces = NetworkInterface .getNetworkInterfaces(); while (networkInterfaces.hasMoreElements()) { NetworkInterface netIf = networkInterfaces.nextElement(); if (isNetworkInterfaceTestable(netIf)) { printNetIfDetails(netIf); ms.setNetworkInterface(netIf); NetworkInterface msNetIf = ms.getNetworkInterface(); if (netIf.equals(msNetIf)) { System.out.println(" OK"); } else { System.out.println("FAILED!!!"); printNetIfDetails(msNetIf); passed = false; } System.out.println("------------------"); } } } catch (IOException e) { e.printStackTrace(); passed = false; } if (!passed) { throw new RuntimeException("Test Fail"); } System.out.println("Test passed "); }
Example #11
Source File: SocketPermissionTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Test public void joinGroupMulticastTest() throws Exception { InetAddress group = InetAddress.getByName("229.227.226.221"); try (MulticastSocket s = new MulticastSocket(0)) { int port = s.getLocalPort(); String addr = "localhost:" + port; AccessControlContext acc = getAccessControlContext( new SocketPermission(addr, "listen,resolve"), new SocketPermission("229.227.226.221", "connect,accept")); // Positive AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> { s.joinGroup(group); s.leaveGroup(group); return null; }, acc); // Negative try { AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> { s.joinGroup(group); s.leaveGroup(group); fail("Expected SecurityException"); return null; }, RESTRICTED_ACC); } catch (SecurityException expected) { } } }
Example #12
Source File: KNXnetIPRouter.java From fuchsia with Apache License 2.0 | 5 votes |
void close(int initiator, String reason, LogLevel level, Throwable t) { if (getState() == CLOSED) return; try { ((MulticastSocket) socket).leaveGroup(multicast); } catch (final IOException e) { logger.warn("problem on leaving multicast group", e); } finally { shutdown(initiator, reason, level, t); } }
Example #13
Source File: TestGangliaContext.java From hadoop with Apache License 2.0 | 5 votes |
@Test public void testShouldSetMulticastSocketTtl() throws Exception { GangliaContext context = new GangliaContext(); ContextFactory factory = ContextFactory.getFactory(); factory.setAttribute("gangliaContext.multicast", "true"); factory.setAttribute("gangliaContext.multicast.ttl", "10"); context.init("gangliaContext", factory); MulticastSocket multicastSocket = (MulticastSocket) context.datagramSocket; assertEquals("Did not set TTL", multicastSocket.getTimeToLive(), 10); }
Example #14
Source File: TestGangliaSink.java From hadoop with Apache License 2.0 | 5 votes |
@Test public void testShouldCreateDatagramSocketByDefault() throws Exception { SubsetConfiguration conf = new ConfigBuilder() .subset("test.sink.ganglia"); GangliaSink30 gangliaSink = new GangliaSink30(); gangliaSink.init(conf); DatagramSocket socket = gangliaSink.getDatagramSocket(); assertFalse("Did not create DatagramSocket", socket == null || socket instanceof MulticastSocket); }
Example #15
Source File: SetGetNetworkInterfaceTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { boolean passed = true; try { MulticastSocket ms = new MulticastSocket(); Enumeration<NetworkInterface> networkInterfaces = NetworkInterface .getNetworkInterfaces(); while (networkInterfaces.hasMoreElements()) { NetworkInterface netIf = networkInterfaces.nextElement(); if (isNetworkInterfaceTestable(netIf)) { printNetIfDetails(netIf); ms.setNetworkInterface(netIf); NetworkInterface msNetIf = ms.getNetworkInterface(); if (netIf.equals(msNetIf)) { System.out.println(" OK"); } else { System.out.println("FAILED!!!"); printNetIfDetails(msNetIf); passed = false; } System.out.println("------------------"); } } } catch (IOException e) { e.printStackTrace(); passed = false; } if (!passed) { throw new RuntimeException("Test Fail"); } System.out.println("Test passed "); }
Example #16
Source File: JdpTestCase.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public void run() throws Exception { log.fine("Test started."); log.fine("Listening for multicast packets at " + connection.address.getHostAddress() + ":" + String.valueOf(connection.port)); log.fine(initialLogMessage()); log.fine("Pause in between packets is: " + connection.pauseInSeconds + " seconds."); startTime = System.currentTimeMillis(); timeOut = connection.pauseInSeconds * TIME_OUT_FACTOR; log.fine("Timeout set to " + String.valueOf(timeOut) + " seconds."); MulticastSocket socket = connection.connectWithTimeout(timeOut * 1000); byte[] buffer = new byte[BUFFER_LENGTH]; DatagramPacket datagram = new DatagramPacket(buffer, buffer.length); do { try { socket.receive(datagram); onReceived(extractUDPpayload(datagram)); } catch (SocketTimeoutException e) { onSocketTimeOut(e); } if (hasTestLivedLongEnough()) { shutdown(); } } while (shouldContinue()); log.fine("Test ended successfully."); }
Example #17
Source File: JdpTestCase.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public void run() throws Exception { log.fine("Test started."); log.fine("Listening for multicast packets at " + connection.address.getHostAddress() + ":" + String.valueOf(connection.port)); log.fine(initialLogMessage()); log.fine("Pause in between packets is: " + connection.pauseInSeconds + " seconds."); startTime = System.currentTimeMillis(); timeOut = connection.pauseInSeconds * TIME_OUT_FACTOR; log.fine("Timeout set to " + String.valueOf(timeOut) + " seconds."); MulticastSocket socket = connection.connectWithTimeout(timeOut * 1000); byte[] buffer = new byte[BUFFER_LENGTH]; DatagramPacket datagram = new DatagramPacket(buffer, buffer.length); do { try { socket.receive(datagram); onReceived(extractUDPpayload(datagram)); } catch (SocketTimeoutException e) { onSocketTimeOut(e); } if (hasTestLivedLongEnough()) { shutdown(); } } while (shouldContinue()); log.fine("Test ended successfully."); }
Example #18
Source File: JdpTestCase.java From hottub with GNU General Public License v2.0 | 5 votes |
public void run() throws Exception { log.fine("Test started."); log.fine("Listening for multicast packets at " + connection.address.getHostAddress() + ":" + String.valueOf(connection.port)); log.fine(initialLogMessage()); log.fine("Pause in between packets is: " + connection.pauseInSeconds + " seconds."); startTime = System.currentTimeMillis(); timeOut = connection.pauseInSeconds * TIME_OUT_FACTOR; log.fine("Timeout set to " + String.valueOf(timeOut) + " seconds."); MulticastSocket socket = connection.connectWithTimeout(timeOut * 1000); byte[] buffer = new byte[BUFFER_LENGTH]; DatagramPacket datagram = new DatagramPacket(buffer, buffer.length); do { try { socket.receive(datagram); onReceived(extractUDPpayload(datagram)); } catch (SocketTimeoutException e) { onSocketTimeOut(e); } if (hasTestLivedLongEnough()) { shutdown(); } } while (shouldContinue()); log.fine("Test ended successfully."); }
Example #19
Source File: SocketPermissionTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@Test public void joinGroupMulticastTest() throws Exception { InetAddress group = InetAddress.getByName("229.227.226.221"); try (MulticastSocket s = new MulticastSocket(0)) { int port = s.getLocalPort(); String addr = "localhost:" + port; AccessControlContext acc = getAccessControlContext( new SocketPermission(addr, "listen,resolve"), new SocketPermission("229.227.226.221", "connect,accept")); // Positive AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> { s.joinGroup(group); s.leaveGroup(group); return null; }, acc); // Negative try { AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> { s.joinGroup(group); s.leaveGroup(group); fail("Expected SecurityException"); return null; }, RESTRICTED_ACC); } catch (SecurityException expected) { } } }
Example #20
Source File: SsdpDiscovery.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
/** * Scans all messages that arrive on the socket and scans them for the * search keywords. The search is not case sensitive. * * @param socket * The socket where the answers arrive. * @param keywords * The keywords to be searched for. * @return * @throws IOException */ private String scanResposesForKeywords(MulticastSocket socket, String... keywords) throws IOException { // In the worst case a SocketTimeoutException raises socket.setSoTimeout(2000); do { logger.debug("Got an answer message."); byte[] rxbuf = new byte[8192]; DatagramPacket packet = new DatagramPacket(rxbuf, rxbuf.length); socket.receive(packet); String foundIp = analyzePacket(packet, keywords); if (foundIp != null) { return foundIp; } } while (true); }
Example #21
Source File: SetGetNetworkInterfaceTest.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { boolean passed = true; try { MulticastSocket ms = new MulticastSocket(); Enumeration<NetworkInterface> networkInterfaces = NetworkInterface .getNetworkInterfaces(); while (networkInterfaces.hasMoreElements()) { NetworkInterface netIf = networkInterfaces.nextElement(); if (isNetworkInterfaceTestable(netIf)) { printNetIfDetails(netIf); ms.setNetworkInterface(netIf); NetworkInterface msNetIf = ms.getNetworkInterface(); if (netIf.equals(msNetIf)) { System.out.println(" OK"); } else { System.out.println("FAILED!!!"); printNetIfDetails(msNetIf); passed = false; } System.out.println("------------------"); } } } catch (IOException e) { e.printStackTrace(); passed = false; } if (!passed) { throw new RuntimeException("Test Fail"); } System.out.println("Test passed "); }
Example #22
Source File: SetGetNetworkInterfaceTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { boolean passed = true; try { MulticastSocket ms = new MulticastSocket(); Enumeration<NetworkInterface> networkInterfaces = NetworkInterface .getNetworkInterfaces(); while (networkInterfaces.hasMoreElements()) { NetworkInterface netIf = networkInterfaces.nextElement(); if (isNetworkInterfaceTestable(netIf)) { printNetIfDetails(netIf); ms.setNetworkInterface(netIf); NetworkInterface msNetIf = ms.getNetworkInterface(); if (netIf.equals(msNetIf)) { System.out.println(" OK"); } else { System.out.println("FAILED!!!"); printNetIfDetails(msNetIf); passed = false; } System.out.println("------------------"); } } } catch (IOException e) { e.printStackTrace(); passed = false; } if (!passed) { throw new RuntimeException("Test Fail"); } System.out.println("Test passed "); }
Example #23
Source File: TestGangliaSink.java From big-c with Apache License 2.0 | 5 votes |
@Test public void testShouldCreateDatagramSocketIfMulticastIsDisabled() throws Exception { SubsetConfiguration conf = new ConfigBuilder() .add("test.sink.ganglia.multicast", false) .subset("test.sink.ganglia"); GangliaSink30 gangliaSink = new GangliaSink30(); gangliaSink.init(conf); DatagramSocket socket = gangliaSink.getDatagramSocket(); assertFalse("Did not create DatagramSocket", socket == null || socket instanceof MulticastSocket); }
Example #24
Source File: UPnPDeviceFinder.java From Android-UPnP-Browser with Apache License 2.0 | 5 votes |
UPnPSocket(InetAddress deviceIp) throws IOException { Log.e(TAG, "UPnPSocket"); mMulticastGroup = new InetSocketAddress(MULTICAST_ADDRESS, PORT); mMultiSocket = new MulticastSocket(new InetSocketAddress(deviceIp, 0)); mMultiSocket.setSoTimeout(MSG_TIMEOUT); }
Example #25
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 #26
Source File: SocketBindingManagerImpl.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
/** {@inheritDoc} */ @Override public MulticastSocket createMulticastSocket(String name, SocketAddress address) throws IOException { Assert.checkNotNullParam("name", name); Assert.checkNotNullParam("address", address); return ManagedMulticastSocketBinding.create(name, this.namedRegistry, address); }
Example #27
Source File: TP.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
private void bindToInterfaces(java.util.List interfaces, MulticastSocket s) throws IOException { SocketAddress group_addr=new InetSocketAddress(diagnostics_addr, diagnostics_port); for(Iterator it=interfaces.iterator(); it.hasNext();) { NetworkInterface i=(NetworkInterface)it.next(); try { s.joinGroup(group_addr, i); if(trace) log.trace("joined " + group_addr + " on " + i.getName()); } catch(IOException e) { log.warn("failed to join " + group_addr + " on " + i.getName() + ": " + e); } } }
Example #28
Source File: One.java From JavaBase with MIT License | 5 votes |
public static void main(String[] args) { try { InetAddress group = InetAddress.getByName(address); MulticastSocket multicastSocket = new MulticastSocket(port); multicastSocket.joinGroup(group); while (true) { byte[] buffer = "One".getBytes(); DatagramPacket packet = new DatagramPacket(buffer, buffer.length, group, port); multicastSocket.send(packet); Thread.sleep(1000); } } catch (Exception e) { log.error("", e); } }
Example #29
Source File: JdpTestCase.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public void run() throws Exception { log.fine("Test started."); log.fine("Listening for multicast packets at " + connection.address.getHostAddress() + ":" + String.valueOf(connection.port)); log.fine(initialLogMessage()); log.fine("Pause in between packets is: " + connection.pauseInSeconds + " seconds."); startTime = System.currentTimeMillis(); timeOut = connection.pauseInSeconds * TIME_OUT_FACTOR; log.fine("Timeout set to " + String.valueOf(timeOut) + " seconds."); MulticastSocket socket = connection.connectWithTimeout(timeOut * 1000); byte[] buffer = new byte[BUFFER_LENGTH]; DatagramPacket datagram = new DatagramPacket(buffer, buffer.length); do { try { socket.receive(datagram); onReceived(extractUDPpayload(datagram)); } catch (SocketTimeoutException e) { onSocketTimeOut(e); } if (hasTestLivedLongEnough()) { shutdown(); } } while (shouldContinue()); log.fine("Test ended successfully."); }
Example #30
Source File: JdpTestCase.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public void run() throws Exception { log.fine("Test started."); log.fine("Listening for multicast packets at " + connection.address.getHostAddress() + ":" + String.valueOf(connection.port)); log.fine(initialLogMessage()); log.fine("Pause in between packets is: " + connection.pauseInSeconds + " seconds."); startTime = System.currentTimeMillis(); timeOut = connection.pauseInSeconds * TIME_OUT_FACTOR; log.fine("Timeout set to " + String.valueOf(timeOut) + " seconds."); MulticastSocket socket = connection.connectWithTimeout(timeOut * 1000); byte[] buffer = new byte[BUFFER_LENGTH]; DatagramPacket datagram = new DatagramPacket(buffer, buffer.length); do { try { socket.receive(datagram); onReceived(extractUDPpayload(datagram)); } catch (SocketTimeoutException e) { onSocketTimeOut(e); } if (hasTestLivedLongEnough()) { shutdown(); } } while (shouldContinue()); log.fine("Test ended successfully."); }