Java Reference
In-Depth Information
message");
// Configure client to be passive and
non.blocking
// client.configureBlocking(false);
client.receive(buffer);
System.out.println("Client Received
Message:");
buffer.flip();
byte[] arr = new byte[buffer.remaining()];
buffer.get(arr, 0, arr.length);
System.out.println(new String(arr));
System.out.println("Disconnecting...performing
a single test pass only");
client.disconnect();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
Next, a server class can be used to broadcast datagrams to the address that multicast
clients are connected to. The following code demonstrates a multicast server:
package org.java8recipes.chapter21.recipe21_4;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;
public class MulticastServer extends Thread {
protected ByteBuffer message = null;
public MulticastServer() {
}
Search WWH ::




Custom Search