Package model

Source Code of model.ReceiveUnicast

package model;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class ReceiveUnicast extends ReceiveHandler implements Runnable{

  private int port;
 
  public ReceiveUnicast(){
    this(Config.defaultPort);
  }
 
  public ReceiveUnicast(int port){ 
    this.port = port;
    Thread t = new Thread(this);
    t.setDaemon(true);
    t.start();   
  }
 
  public void run(){
    DatagramSocket socket = null;
    try {
      socket = new DatagramSocket(port);     
    } 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.ReceiveUnicast

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.