Java applet不会通过套接字连接到主机

时间:2014-02-28 04:29:09

标签: java sockets applet ip

我有一个有趣的困境......我有一个java applet,它将通过调用getCodeBase().getHost()通过套接字连接到它的主机(一个java应用程序)。我有一个使用IIS设置的Web服务器和使用no-ip的动态DNS设置,当我通过外部IP打开applet时,它将在端口44444上创建一个到主机的套接字连接但是使用ip,matrix159.no -ip.biz是动态主机名,导致套接字无法连接。对不起,如果这个问题措辞不正确,但我已经搜索过,找不到任何答案!

 private void submitButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
    try 
    {

        System.out.println(getCodeBase().toString() + " " + "This is codebase");
        String host = getCodeBase().getHost();
        System.out.println(host);
        socket = new Socket(getCodeBase().getHost(), 44444);
        System.out.println("Socket opened");
        if(host == null)System.out.println("Host was null");
        outputStream = new DataOutputStream(socket.getOutputStream());
        outputStream.writeUTF(buttonGroup1.getSelection().getActionCommand());
    }
    catch(UnknownHostException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
    catch (IOException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
}

这是它产生的错误。

Exception in thread "Thread-27" java.security.AccessControlException: access denied (java.net.SocketPermission 50.124.10.35:44444 connect,resolve)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:376)
at java.security.AccessController.checkPermission(AccessController.java:549)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at sun.plugin2.applet.Applet2SecurityManager.checkPermission(Applet2SecurityManager.java:236)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1034)
at sun.plugin2.applet.Applet2SecurityManager.checkConnect(Applet2SecurityManager.java:568)
at java.net.Socket.connect(Socket.java:522)
at java.net.Socket.connect(Socket.java:476)
at java.net.Socket.<init>(Socket.java:373)
at java.net.Socket.<init>(Socket.java:187)
at myapplet.Main$3.run(Main.java:185)
at java.lang.Thread.run(Thread.java:695)

0 个答案:

没有答案