import java.io.*;
import java.net.*;
import java.util.*;
import Multi;
class prova{
public static void main(String[] args) throws IOException {
String msg = "Hello";
InetAddress group = InetAddress.getByName("228.5.6.7");
MulticastSocket s = new MulticastSocket(6789);
s.joinGroup(group);
DatagramPacket hi = new DatagramPacket(msg.getBytes(),
msg.length(),group, 6789);
s.send(hi);
// get their responses!
byte[] buf = new byte[1000];
DatagramPacket recv = new DatagramPacket(buf, buf.length);
s.receive(recv);
// OK, I'm done talking - leave the group...
s.leaveGroup(group);
}
}
Se lo eseguo in localhost ottengo:
Exception in thread "main" java.net.BindException: Cannot assign requested
address:
set socket option failed
at java.net.PlainDatagramSocketImpl.join(Native Method)
at java.net.MulticastSocket.joinGroup(MulticastSocket.java:229)
at prova.main(prova.java:13)
Se lo eseguo collegandomi a internet l'applicazione non termina sembra che
si blocchi sulla ricezione.
Lo sto eseguendo su windows xp professional.
Qualsiasi suggerimento, grazie.
Alessio.