1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-11-25 06:17:33 +00:00

* Allow specifying the bind address that picoweb will listen on (e.g. -picoweb:8000:localhost).

* Change picoweb server to print the actual port being listened on when port 0 was specified.
This commit is contained in:
matthew16550 2021-02-12 17:19:03 +11:00
parent 0dc13cccf2
commit f850b5f400
3 changed files with 15 additions and 12 deletions

View File

@ -79,6 +79,7 @@ public class Option {
private boolean textProgressBar = false;
private int nbThreads = 0;
private int ftpPort = -1;
private String picowebBindAddress = null;
private int picowebPort = -1;
private boolean hideMetadata = false;
private boolean checkMetadata = false;
@ -370,12 +371,9 @@ public class Option {
this.ftpPort = Integer.parseInt(s.substring(x + 1));
}
} else if (StringUtils.goLowerCase(s).startsWith("-picoweb")) {
final int x = s.indexOf(':');
if (x == -1) {
this.picowebPort = 8080;
} else {
this.picowebPort = Integer.parseInt(s.substring(x + 1));
}
final String[] parts = s.split(":");
this.picowebPort = parts.length > 1 ? Integer.parseInt(parts[1]) : 8080;
this.picowebBindAddress = parts.length > 2 ? parts[2] : null;
} else if (s.startsWith("-c")) {
s = s.substring(2);
config.add(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(s));
@ -403,6 +401,10 @@ public class Option {
return ftpPort;
}
public String getPicowebBindAddress() {
return picowebBindAddress;
}
public int getPicowebPort() {
return picowebPort;
}

View File

@ -334,9 +334,7 @@ public class Run {
}
private static void goPicoweb(Option option) throws IOException {
final int picoWebport = option.getPicowebPort();
System.err.println("webPort=" + picoWebport);
PicoWebServer.startServer(picoWebport);
PicoWebServer.startServer(option.getPicowebPort(), option.getPicowebBindAddress());
}
public static void printFonts() {

View File

@ -42,6 +42,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;
@ -72,11 +73,13 @@ public class PicoWebServer implements Runnable {
}
public static void main(String[] args) throws IOException {
startServer(8080);
startServer(8080, null);
}
public static void startServer(final int port) throws IOException {
final ServerSocket serverConnect = new ServerSocket(port);
public static void startServer(final int port, final String bindAddress) throws IOException {
final InetAddress bindAddress1 = bindAddress == null ? null : InetAddress.getByName(bindAddress);
final ServerSocket serverConnect = new ServerSocket(port, 50, bindAddress1);
System.err.println("webPort=" + serverConnect.getLocalPort());
while (true) {
final PicoWebServer myServer = new PicoWebServer(serverConnect.accept());
final Thread thread = new Thread(myServer);