开发者

Java Socket permission : applet isn't initialized

开发者 https://www.devze.com 2023-03-03 11:15 出处:网络
Following is the part of my error. Because of this error my applet isn\'t initialized. The following code is part of the init() method:

Following is the part of my error. Because of this error my applet isn't initialized. The following code is part of the init() method:

    Socket sock;
    try {
        sock = new Socket("localhost", 1307);
        out = new PrintWriter(sock.getOutputStream(), true);
        in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
    }
    ca开发者_开发百科tch (UnknownHostException e) { }
    catch (IOException e) { }

I m getting the following error:

java.security.AccessControlException: access denied (java.net.SocketPermission 1
127.0.0.1 resolve)
        at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:323)
        at java.security.AccessController.checkPermission(AccessController.java:
546)
        at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
        at java.lang.SecurityManager.checkConnect(SecurityManager.java:1031)
        at java.net.InetAddress.getAllByName0(InetAddress.java:1145)
        at java.net.InetAddress.getAllByName(InetAddress.java:1083)
        at java.net.InetAddress.getAllByName(InetAddress.java:1019)
        at java.net.InetAddress.getByName(InetAddress.java:969)
        at java.net.InetSocketAddress.<init>(InetSocketAddress.java:124)
        at java.net.Socket.<init>(Socket.java:186)
        at Alice.init(Alice.java:103)
        at sun.applet.AppletPanel.run(AppletPanel.java:424)
        at java.lang.Thread.run(Thread.java:619)

I am running another program on another JVM. I am trying to connect both using 1307 port on localhost.


Applets may not connect to any host except the one they were loaded from (due to security reasons).

If you want to do that anyway, you must sign your applet.


This is a security issue that does not let you create a connection from within an applet. Applets in general are not allowed to open socket connections.

To be more specific, you can only open connections to the server that served the applet.

0

精彩评论

暂无评论...
验证码 换一张
取 消