Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.net.DatagramSocket;
import java.net.SocketException;

import java.util.Random;

public class Main {
    private static int port = 0;
    private static DatagramSocket datagramSocket;

    private static void BindPort() {
        Random random = new Random();
        port = random.nextInt(65535);

        try {
            datagramSocket = new DatagramSocket(port);
        } catch (SocketException e) {
            // TODO Auto-generated catch block
            BindPort();
        }
    }
}