简体   繁体   English

Java Socket Bridge无法连接

[英]Java Socket Bridge unable to connect

I have a project for varsity where we should use Java Socket Bridge to connect to a chat server (that is how I understand the project at least). 我有一个用于大学的项目,我们应该使用Java Socket Bridge连接到聊天服务器(至少我是这样了解该项目的)。

So according to this github page, you should add this to your head 因此,根据 github页面,您应该将此添加到您的头部

<script type="text/javascript" src="java_socket_bridge.js"></script>

and this to your body 这对你的身体

<applet id="JavaSocketBridge" archive="JavaSocketBridge.jar" code="JavaSocketBridge.class" width="0" height="0"></applet>

I have done so and I also ran the make.sh file to produce the jar file. 我这样做了,并且我还运行了make.sh文件来生成jar文件。 Here is my php file: 这是我的php文件:

<?php session_start(); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="utf-8">
        <script type="text/javascript" src="java_socket_bridge.js"></script>
        <title>ValidateLogin</title>
    </head>
    <body>
        <?php
            $ip = $_POST['ip'];
            $port = $_POST['port'];
            $_SESSION['sid'] = session_id();
            $_SESSION['ip'] = $ip;
            $_SESSION['port'] = $port;
            // header("location: Game.php");
            echo '  <applet id="JavaSocketBridge" code="JavaSocketBridge.class" archive="JavaSocketBridge.jar" height="0" width="0"></applet>';
            echo "  <script>
                        console.log(document.getElementById('JavaSocketBridge'));
                        if(socket_connect('".$ip."', '".$port."'))
                        {
                            console.log('connected!');
                        }
                        else
                        {
                            console.log('not connected!');
                        }
                    </script>";
        ?>
    </body>
</html>

So my problem is that when I call the socket_connect() function my web console displays 所以我的问题是,当我调用socket_connect()函数时,我的Web控制台会显示

"Java Socket Bridge cannot connect until the applet has loaded" "not connected!" “ Java Socket Bridge在小程序加载之前无法连接”“未连接!”

I have tried calling the java_socket_bridge_ready() function (although it was not specified to do so) and then the web console displays: 我尝试调用java_socket_bridge_ready()函数(尽管未指定这样做),然后Web控制台显示:

TypeError: get_java_socket_bridge(...).connect is not a function TypeError:get_java_socket_bridge(...)。connect不是一个函数

on line 39 of the java_socket_bridge.js file. 在java_socket_bridge.js文件的第39行。

I can't find any help on Google on this issue I've been looking all day. 我整天都在寻找关于此问题的Google方面的任何帮助。 I am using Ubuntu 14.04 and the latest firefox and XAMPP to run my webserver. 我正在使用Ubuntu 14.04和最新的firefox和XAMPP来运行我的Web服务器。

I figured out that I have to enable Java in my browser. 我发现必须在浏览器中启用Java。 I used this page from Java's website on how to install and enable Java in my browser. 我在Java网站上使用了页面,了解如何在浏览器中安装和启用Java。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM