how to set java bridge http local as static port?

161 Views Asked by At

I have a question about php/java bridge. I have run it and I got prompt like this one

1 I want to set this for only run in http_local port 8080 and not show again the prompt choice? I have a search in my php/javabridge I cannot get the location of class which call this prompt and set the http_local port 8080 how to set it? it is possible? if it is possible where is the code must I edit it?

after I check the code for a call this prompt is from standalone.java

public void init(final String[] s) {
        String sockname = null;
        int logLevel = -1;
        final String tcpSocketName = "9267";
        if (s.length > 3) {
            this.checkOption(s);
        }
        try {
            if (s.length > 0) {
                sockname = s[0];
                if (sockname.startsWith("-")) {
                    this.checkOption(s);
                }
            }
            try {
                if (s.length > 1) {
                    logLevel = Integer.parseInt(s[1]);
                }
            }
            catch (NumberFormatException e2) {
                this.usage();
            }
            catch (Throwable t) {
                t.printStackTrace();
            }
            if (s.length == 0) {
                try {
                    final int tcpSocket = Integer.parseInt(tcpSocketName);
                    final int freeJavaPort = findFreePort(tcpSocket);
                    final int freeHttpPort = findFreePort(8080);
                    final int freeHttpsPort = findFreePort(8443);
                    final Object result = JOptionPane.showInputDialog(null, "Start a socket listener on port", "Starting the PHP/Java Bridge ...", 3, null, new String[] { "INET_LOCAL:" + freeJavaPort, "INET:" + freeJavaPort, "HTTP_LOCAL:" + freeHttpPort, "HTTP:" + freeHttpPort, "HTTPS_LOCAL:" + freeHttpsPort, "HTTPS:" + freeHttpsPort }, "HTTP_LOCAL:" + freeHttpPort);
                    if (result == null) {
                        System.exit(0);
                    }
                    sockname = result.toString();
                }
                catch (Throwable t2) {}
            }
            if (s.length == 0) {
                TCPServerSocket.TCP_PORT_BASE = Integer.parseInt(tcpSocketName);
            }
            if (checkServlet(logLevel, sockname, s)) {
                return;
            }
            final ISocketFactory socket = bind(logLevel, sockname);
            if ("true".equals(System.getProperty("php.java.bridge.test.startup"))) {
                System.exit(0);
            }
            JavaBridge.initLog(String.valueOf(socket), logLevel, s);
            JavaBridge.init(socket, logLevel, s);
        }
        catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

so this is possible to set only like this code for only run in http_local 8080? I use javabridge from maven

1

There are 1 best solutions below

1
glegshot On

To make the port to be a static value and the prompt not to popup,you can make the below code change

    if (s.length == 0) {
            try {
                final int tcpSocket = Integer.parseInt(tcpSocketName);
                final int freeJavaPort = findFreePort(tcpSocket);
                final int freeHttpPort = findFreePort(8080);
                final int freeHttpsPort = findFreePort(8443);
                //comment the JOptionPane to disable the dialog prompt
                /*final Object result = JOptionPane.showInputDialog(null, "Start a socket listener on port", "Starting the PHP/Java Bridge ...", 3, null, new String[] { "INET_LOCAL:" + freeJavaPort, "INET:" + freeJavaPort, "HTTP_LOCAL:" + freeHttpPort, "HTTP:" + freeHttpPort, "HTTPS_LOCAL:" + freeHttpsPort, "HTTPS:" + freeHttpsPort }, "HTTP_LOCAL:" + freeHttpPort);
                if (result == null) {
                    System.exit(0);
                }*/
                sockname = "8080"; //<--hardcode the sockname variable with the desired valid port value
            }
            catch (Throwable t2) {}
        }