Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

current port used by the Java application

//Get the current port used by a Java application using socket programming in Java
private static int getPort() {
	    MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
	    Set<ObjectName> objectNames = null;
	    try {
	        objectNames = beanServer.queryNames(new ObjectName("*:type=ProtocolHandler,*"),
	                Query.match(Query.attr("name"), Query.value(""https-*")));
	    } catch (MalformedObjectNameException e) {
	        log.error("SecuredPort not defined!", e);
	        return 0;
	    }

	    return Integer.parseInt(objectNames.iterator().next().getKeyProperty("port"));
	}
Comment

PREVIOUS NEXT
Code Example
Java :: Send keybord key P in selenium java 
Java :: java file creation date 
Java :: JSONObject append 
Java :: android list newline 
Java :: react-native force light mode 
Java :: math.sin in java 
Java :: java use space in enums 
Java :: android press back 2 times to exit 
Java :: initialize an arraylist in java in java 
Java :: get width and height of screen libgdx 
Java :: javaparser 
Java :: java resultset to table 
Java :: arraylist replace 
Java :: double if statement java 
Java :: hashmap put method 
Java :: How do I make my Android app scrollable? 
Java :: java get parent class 
Java :: java break string at comma 
Java :: java timeout exception 
Java :: how to skip a line with a filewriter java 
Java :: custom dialog in android 
Java :: array index out of bound exception in java 
Java :: binary to string java 
Java :: unresolved reference activity_main 
Java :: zoneddatetime java 
Java :: java @override annotation 
Java :: Exception handling using try...catch 
Java :: java map sorted by key 
Java :: javafx listview of objects 
Java :: android java how to stop users fromgoing back too much 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =