package model;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
public class ReceiveMulticast extends ReceiveHandler implements Runnable{
private int port;
private String ip;
public ReceiveMulticast(String ip, int port){
this.ip = ip;
this.port = port;
Thread t = new Thread(this);
t.setDaemon(true);
t.start();
}
public void run(){
MulticastSocket socket = null;
try {
socket = new MulticastSocket(port);
socket.joinGroup(InetAddress.getByName(ip));
} catch (IOException e1) {
e1.printStackTrace();
}
byte buffer[] = new byte[65507];
DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
while(true){
try {
socket.receive(packet);
handlePacket(packet);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}