Package model

Source Code of model.ReceiveMulticast

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();
      }
    }
  }

 
 
}
TOP

Related Classes of model.ReceiveMulticast

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.