All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.freemanan.starter.grpc.extensions.test.NetUtil Maven / Gradle / Ivy

There is a newer version: 3.1.8
Show newest version
package com.freemanan.starter.grpc.extensions.test;

import java.io.IOException;
import java.net.ServerSocket;
import lombok.experimental.UtilityClass;

/**
 * @author Freeman
 */
@UtilityClass
public class NetUtil {

    /**
     * Get a random port.
     *
     * @return port
     */
    public static int getRandomPort() {
        try (ServerSocket ss = new ServerSocket(0)) {
            return ss.getLocalPort();
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy