package org.kne.cloud.network.klalb;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.SocketException;

import org.kne.cloud.network.VirtualDatagramSocket;
import org.kne.cloud.network.VirtualDatagramSocketImpl;
import org.pcap4j.core.Inets;

public class KLALBVirtualDatagramSocket extends VirtualDatagramSocket {

    private KLALBController controller;
    
    // 默认构造函数
    public KLALBVirtualDatagramSocket(KLALBController controller) throws SocketException {
       this(controller,new InetSocketAddress(0));
    }

    // 绑定到指定Socket地址
    public KLALBVirtualDatagramSocket(KLALBController controller, SocketAddress bindaddr) throws SocketException {
        super(controller.createVirtualDatagramSocketImpl());
		this.controller = controller;
        if (bindaddr != null) {
            bind(bindaddr);
        }
    }

    // 绑定到指定端口
    public KLALBVirtualDatagramSocket(KLALBController controller, int port) throws SocketException {
        this(controller, port, null);
    }

    // 绑定到指定端口和本地地址
    public KLALBVirtualDatagramSocket(KLALBController controller, int port, InetAddress laddr) throws SocketException {
        this(controller);
        if (laddr == null) {
            bind(new InetSocketAddress(port));
        } else {
            bind(new InetSocketAddress(laddr, port));
        }
    }

    
}