All Classes Functions Pages
Examples

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;
//sending a message
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{
//create an multicast socket object
MulticastSocket mSocket=new MulticastSocket();
//join the group...
mSocket.join("ip://239.0.0.1:1234");
System.out.println("joined ip://239.0.0.1:1234");
while(true){
//...and receive the message
String str=new String(mSocket.receive().getContent());
System.out.println(str);
}
}
}