Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problemi con MulticastSocket

0 views
Skip to first unread message

Alessio

unread,
Sep 17, 2002, 4:17:55 AM9/17/02
to
Stavo cercando di capire come funziona la classe MulticastSocket : ho
provato un esempio che ho trovato nella documentazione, ma non funziona.
Riporto l'esempio:


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.

0 new messages