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.net.ServerSocket;
import lombok.SneakyThrows;
import lombok.experimental.UtilityClass;

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy