package org.kne.cloud.network.nathole;

import java.io.IOException;
import java.net.BindException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.MulticastSocket;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketOption;
import java.net.SocketOptions;
import java.nio.channels.SocketChannel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class UDPNatholeTest {
	public static ExecutorService exc=Executors.newCachedThreadPool();
	public static void main(String[] args) throws IOException {
		InetAddress addr=InetAddress.getByName("10.235.16.1");
		for (int i1 = 1024; i1 < 65536; i1++) {
		MulticastSocket ms=new MulticastSocket(i1);
		//ms.setReuseAddress(true);
		ms.setSendBufferSize(65536);
		DatagramPacket fp=new DatagramPacket(new byte[1], 1, addr, 13000);
		ms.send(fp);
		new Thread(()->{
			DatagramPacket rp=new DatagramPacket(new byte[10], 10);
			try {
				ms.receive(rp);
				System.err.println(rp.getAddress());
				System.err.println(rp.getLength());
				System.exit(0);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}).start();
		System.out.println(i1);
		}
	}
}
