require_once(): Failed opening required on javabridge

384 views Asked by At

I have question.

I have setup my java and my java bridge. I have run and open port at 8080 but when I run my php code I got error here:

Warning: require_once(http://localhost:8080/JavaBridge/java/Java.inc): failed to open stream: HTTP request failed! in C:\xampp\htdocs\mt4\test2.php on line 3

Fatal error: require_once(): Failed opening required 'http://localhost:8080/JavaBridge/java/Java.inc' (include_path='.;C:\php\pear') in C:\xampp\htdocs\mt4\test2.php on line 3

at my code for choose port I use manual port using this code,

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();
                sockname = "8080";
            }
            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);
    }
}

I use xampp for run php. My tomcat have opened port 8080 and at php.ini I have setup allow_url_include=On but still cannot connect to my javaBridge port why like that ? Can anyone help me for fix this problem

if I use this code,

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();
                   // sockname = "8080";
                }

but I must to choose witch port will I use for... so I need to set port use static port.

Here my class of TCPServerSocket,

// 
// Decompiled by Procyon v0.5.36
// 

package php.java.bridge.http;

import java.net.Socket;
import java.net.UnknownHostException;
import java.net.InetAddress;
import java.io.IOException;
import java.net.ServerSocket;

public class TCPServerSocket implements ISocketFactory
{
    public static int TCP_PORT_BASE;
    private ServerSocket sock;
    private int port;
    boolean local;
    
    public static ISocketFactory create(String name, final int backlog) throws IOException {
        boolean local = false;
        if (name == null) {
            throw new NullPointerException("name");
        }
        if (name.startsWith("INET:")) {
            name = name.substring(5);
        }
        else if (name.startsWith("INET_LOCAL:")) {
            local = true;
            name = name.substring(11);
        }
        final int p = Integer.parseInt(name);
        final TCPServerSocket s = new TCPServerSocket(p, backlog, local);
        return s;
    }
    
    private ServerSocket newServerSocket(final int port, final int backlog) throws IOException {
        try {
            if (this.local) {
                return new ServerSocket(port, backlog, InetAddress.getByName("127.0.0.1"));
            }
        }
        catch (UnknownHostException ex) {}
        return new ServerSocket(port, backlog);
    }
    
    private void findFreePort(final int start, final int backlog) {
        int port = start;
        while (port < start + 100) {
            try {
                this.sock = this.newServerSocket(port, backlog);
                this.port = port;
                return;
            }
            catch (IOException e) {
                ++port;
                continue;
            }
        }
    }
    
    private TCPServerSocket(final int port, final int backlog, final boolean local) throws IOException {
        this.local = local;
        if (port == 0) {
            this.findFreePort(TCPServerSocket.TCP_PORT_BASE, backlog);
        }
        else {
            this.sock = this.newServerSocket(port, backlog);
            this.port = port;
        }
    }
    
    @Override
    public void close() throws IOException {
        this.sock.close();
    }
    
    @Override
    public Socket accept() throws IOException {
        final Socket s = this.sock.accept();
        s.setTcpNoDelay(true);
        return s;
    }
    
    @Override
    public String getSocketName() {
        return String.valueOf(this.port);
    }
    
    @Override
    public String toString() {
        return (this.local ? "INET_LOCAL:" : "INET:") + this.getSocketName();
    }
    
    static {
        TCPServerSocket.TCP_PORT_BASE = 9267;
    }
}
0

There are 0 answers