Examples
Here are two little example, to copy paste in your code to try the library. Make sure your middleware is running (Have a look here).
SimpleSender.java;
public class SimpleSender {
public static void main(String[] args){
try{
URI uri = new URI("ip://239.0.0.1:1234");
MulticastSocket mSocket=new MulticastSocket();
for (int i = 0; i < 100; i++) {
String hello_world = "Hello World " + "Nr. " + i;
mSocket.send(uri, hello_world.getBytes());
System.out.println(hello_world);
Thread.sleep(10);}
}
catch(Exception e){
e.printStackTrace();
}
}
}
SimpleReceiver.java
public class SimpleReceiver {
public static void main(String[] args) throws Exception{
MulticastSocket mSocket=new MulticastSocket();
mSocket.join("ip://239.0.0.1:1234");
System.out.println("joined ip://239.0.0.1:1234");
while(true){
String str=new String(mSocket.receive().getContent());
System.out.println(str);
}
}
}