Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat's the difference between http://localhost:8000/ and http://127.0.0.1:8000/ for Java Applets
    primarykey
    data
    text
    <p>I have a question/problem related to Java Applet security...<br> I use the Applet that has to take files from server (ASP.NET) and represent the information from it. Applet take files using the code:</p> <pre><code>URL u = new URL(getCodeBase(), filename); BufferedReader d = new BufferedReader(new InputStreamReader(u.openStream())); </code></pre> <p>This code appears in two places:</p> <ol> <li><code>Init()</code> method </li> <li>Some another method <code>Test()</code> that called manually from JavaScript </li> </ol> <p>So, when I try to load the page with Applet using the URL <code>http://127.0.0.1:8000/Test.aspx</code>, everything works fine and I can read file content from both methods. But if I change the URL on <code>http://localhost:8000/</code>, only the first method works properly and I can get files content and for the second one I get the next error message in JavaConsole:</p> <blockquote> <p>java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:8000 connect,resolve)</p> </blockquote> <p>What it the difference in this case? Why 'localhost' is impossible in this case? Is there any way how to grant access to 'localhost' the same as 127.0.0.1?</p> <p>here is simplest applet's example:</p> <pre><code>public class TestApplet extends Applet { public void init() { System.out.println( "init..."); readDocument(); } public void readDocument() { System.out.println( "read test.txt file..."); URL base = getCodeBase(); String filename = "test.txt"; try { URL u = new URL(base, filename); BufferedReader d = new BufferedReader(new InputStreamReader(u.openStream())); System.out.println(d.readLine()); System.out.println("Done!"); } catch (Exception e) { e.printStackTrace(); } } } </code></pre> <p>and next code used on the client side:</p> <pre><code>&lt;applet archive="/Content/test.jar" code="test.TestApplet.class" name="testApplet" mayscript&gt;&lt;/applet&gt; &lt;script language="javascript" type="text/javascript"&gt; $(document).ready(function () { var testApplet = document.testApplet; testApplet.readDocument(); }); &lt;/script&gt; </code></pre> <p>this code works perfectly when I try to use <a href="http://127.0.0.1:8000/Test.aspx" rel="nofollow">http://127.0.0.1:8000/Test.aspx</a> and doesn't work when I user <a href="http://localhost:8000/Test.aspx" rel="nofollow">http://localhost:8000/Test.aspx</a>. I java console I see the next:</p> <pre><code>init... read test.txt file... some text... Done! read test.txt file... java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:8000 connect,resolve) at java.security.AccessControlContext.checkPermission(Unknown Source) at java.security.AccessController.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPermission(Unknown Source) at java.lang.SecurityManager.checkConnect(Unknown Source) at sun.plugin2.applet.Applet2SecurityManager.checkConnect(Unknown Source) at java.net.Socket.connect(Unknown Source) at sun.net.NetworkClient.doConnect(Unknown Source) at sun.net.www.http.HttpClient.openServer(Unknown Source) at sun.net.www.http.HttpClient.openServer(Unknown Source) at sun.net.www.http.HttpClient.&lt;init&gt;(Unknown Source) at sun.net.www.http.HttpClient.New(Unknown Source) at sun.net.www.http.HttpClient.New(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source) at java.net.URL.openStream(Unknown Source) at test.TestApplet.readDocument(TestApplet.java:30) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at sun.plugin.javascript.JSInvoke.invoke(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at sun.plugin.javascript.JSClassLoader.invoke(Unknown Source) at sun.plugin2.liveconnect.JavaClass$MethodInfo.invoke(Unknown Source) at sun.plugin2.liveconnect.JavaClass$MemberBundle.invoke(Unknown Source) at sun.plugin2.liveconnect.JavaClass.invoke0(Unknown Source) at sun.plugin2.liveconnect.JavaClass.invoke(Unknown Source) at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$DefaultInvocationDelegate.invoke(Unknown Source) at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo.doObjectOp(Unknown Source) at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$LiveConnectWorker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) </code></pre> <p>P.S.: Applet is signed.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload