user661921
user661921

Reputation: 21

Java Socket permission : applet isn't initialized

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()));
    }
    catch (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.

Upvotes: 0

Views: 1353

Answers (2)

Vern
Vern

Reputation: 2413

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.

Upvotes: 1

Joachim Sauer
Joachim Sauer

Reputation: 308001

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.

Upvotes: 1

Related Questions