Ajuda com Multicast

4 respostas
F

Olá, pessoas,

eu tô tentando compilar o seguinte código

// Import some needed classes
import sun.net.*;
import java.net.*;

public class ChatServer {
	public static void main(String args[])
	{
		// Which port should we listen to
	       int port = 5000;
	       // Which address
	       String group = "225.4.5.6";

		// Create the socket and bind it to port 'port'.
	       MulticastSocket s = new MulticastSocket(port);

		// join the multicast group
	        s.joinGroup(InetAddress.getByName(group));
	       // Now the socket is set up and we are ready to receive packets

		// Create a DatagramPacket and do a receive
		byte buf[] = new byte[1024];
 		DatagramPacket pack = new DatagramPacket(buf, buf.length);
	        s.receive(pack);

		// Finally, let us do something useful with the data we just received,
	      // like print it on stdout :-)
	      System.out.println("Received data from: " + pack.getAddress().toString() +
      			    ":" + pack.getPort() + " with length: " +
      			    pack.getLength());
	      System.out.write(pack.getData(),0,pack.getLength());
	      System.out.println();

		 // And when we have finished receiving data leave the multicast group and
      		// close the socket
	        s.leaveGroup(InetAddress.getByName(group));
	      s.close();
	 }
}

mas eu obtenho o erro

The import sun.net cannot be resolved

Alguém sabe o que eu fiz de errado?

Obrigada ^^

4 Respostas

E

No caso, esse teu chat seria ponto-a-ponto, sem centralização em um servidor?

F

A princípio, eu só queria testar o funcionamento do Multicast (pq eu tô acostumada a usar só em C) num cliente-servidor simples… futuramente a idéia é um ponto-a-ponto =P

Esse código não é meu, achei no google, só queria compilar ^^

F

simples, só comentei a linha
import sun.net.*;
e resolveu o meu problema o.Ô

E

Na verdade eu desconheço completamente este pacote :wink:

Criado 15 de maio de 2008
Ultima resposta 16 de mai. de 2008
Respostas 4
Participantes 2