Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (429)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (468)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  applets no longer have permission to access "localhost"???  (Read 5442 times)
0 Members and 1 Guest are viewing this topic.
Offline neoskunk

Junior Member





« Posted 2009-05-13 12:23:22 »

recently i was trying to test a game i have been working on.   i have been working on this game on and off for a while and it involves sockets.  to test the game i usually just run the server application and the applet connects to "localhost".  however it seems with a recent update of java, applets loaded on the same machine no longer have permission to access "localhost".  whats the best way around this for me to keep testing my game?  if at all possible i do not want to modify the permissions file.  if i ever put this game on the net applets are still allowed access back to the host server without modification of the permissions file right?

thanks,
scov
Offline Markus_Persson

JGO Wizard


Medals: 12
Projects: 19


Mojang Specifications


« Reply #1 - Posted 2009-05-14 09:49:45 »

Being able to access both localhost and the server the applet was loaded from sounds like a pretty huge security flaw, so I wouldn't count on being able to do that ever again.
Were you testing it on a locally hosted server before?

Play Minecraft!
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 613
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #2 - Posted 2009-05-14 10:01:58 »

Make sure you only use the hostname provided by applet.getDocumentBase().getHost().

If you try to connect to 127.0.0.1 but you're serving from 192.168.x.x or 10.0.0.x, then you get a AccessControlException, like you should.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline neoskunk

Junior Member





« Reply #3 - Posted 2009-05-14 18:52:13 »

im still relatively new to java but a month or two ago i could run my server application and the game applet all on my computer.  Im using sockets and the code in the server looks like

1  
ssock = new ServerSocket(4444); 


4444 or any arbitrary port number used to work.

and the applet has code like

1  
sock = new Socket("localhost",4444);


i dont have a server i was just trying to simulate internet play all on the same machine so i could test my game.  this method worked a month or two ago and i recently tried to run my game again(no changes to any code) and i get the AccessControlException....

whats the best way for me to keep simulating internet play all on the same machine?




Offline SimonH
« Reply #4 - Posted 2009-05-14 19:02:06 »

If you want to use sockets you'll need to sign the applet to give it permission to do so.
Sockets are not ideal for applets for this reason, but if people are prepared to accept your certificate (a la Runescape) it'll work fine.

People make games and games make people
Offline Wildern

Junior Member





« Reply #5 - Posted 2009-05-14 19:15:27 »

I agree that you should use something like
1  
new Socket(applet.getDocumentBase().getHost(),4444)

instead of localhost.  It should wind up being localhost if you are running it all on the same machine.
Offline neoskunk

Junior Member





« Reply #6 - Posted 2009-05-14 20:24:52 »

even with getHost() i dont think it will work because of a recent java update.  as for signing i thought applets could connect back to the host server without being signed???

if sockets are not ideal for applets what is a better approach?  and if the applet must be signed what exactly does that mean and how do you do it?
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 613
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #7 - Posted 2009-05-14 21:46:54 »

even with getHost() i dont think it will work because ...

For the sake of fluffy bunnies... try it.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline neoskunk

Junior Member





« Reply #8 - Posted 2009-05-14 23:53:33 »

i did and it still doesn't work... 

this is what i tried....

the applet looks like this.....

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
import java.applet.*;
import java.net.*;
import java.io.*;

public class testing extends Applet
{
    Socket s = null;
       
    public void init()
    {
        try
        {
            s = new Socket(getDocumentBase().getHost(),4444);
        }
        catch (IOException e)
        {}
       
    }
   
}
           


and the server application looks like this....

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
import java.applet.*;
import java.net.*;
import java.io.*;

public class server
{
    public static void main (String args[])
    {
        ServerSocket s = null;
        Socket c = null;
       
        try
        {
            s = new ServerSocket(4444);
        }
        catch(IOException e)
        {
            System.out.println("error");
            System.exit(1);
        }
       
        try
        {
            c = s.accept();
        }
        catch (IOException ex)
        {
            System.out.println("error2");
            System.exit(1);
        }
       
        System.out.println("someone successfully connected");
       
    }
}
         


if this was successfull i should see a message saying someone connected and i do not...

also no exceptions are thrown on the application side but i guess you wouldn't expect any there....
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 613
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #9 - Posted 2009-05-15 00:06:00 »

Sorry, you are also restricted to the port you are hosting your applet on.

If your applet is loaded on a webpage on port 80, you can only connect to port 80

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline neoskunk

Junior Member





« Reply #10 - Posted 2009-05-15 00:57:19 »

ok well since my applet isn't loaded on any webpage what does that mean?  im just generating the applet using an applet viewer (ie. BlueJ).  i tried port 80 it still does the same thing.  i dont understand why this is so complicated.  does no one create internet games using applets?  if so how do they test them?
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 613
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #11 - Posted 2009-05-15 00:59:45 »

I have an applet that connects to its host:

http://www.indiespot.net/files/spooky_applet.html

Sourcecode provided.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Mr_Light

Senior Member




shiny.


« Reply #12 - Posted 2009-05-15 01:00:20 »

And that's why you can connect to a sql server on a totally different port?

You can only connect to localhost if the applet is hosted on the client. Better said you can only connect to the host that hosts the applet. Only if the host that hosts the applet happens to be the localhost can you connect to it.

There is a difference between:
- where the code is run, dictates what localhost is
- where the code orientates from, dedicates where you can connect to.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline neoskunk

Junior Member





« Reply #13 - Posted 2009-05-15 01:25:15 »

given the code i posted above and what you just said mr.light shouldn't my program run?
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 613
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #14 - Posted 2009-05-15 01:31:41 »

And that's why you can connect to a sql server on a totally different port?
* Riven screwed up. I was confused with AJAX

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline SimonH
« Reply #15 - Posted 2009-05-15 05:00:04 »

even with getHost() i dont think it will work because of a recent java update.  as for signing i thought applets could connect back to the host server without being signed???

if sockets are not ideal for applets what is a better approach?  and if the applet must be signed what exactly does that mean and how do you do it?
An applet can connect back only to it's host and only on 'the web' port 80. Signed applets can connect to any host, any port, anywhere.
Free server & signed applets - if you want fast comms you'll need both!

People make games and games make people
Offline Markus_Persson

JGO Wizard


Medals: 12
Projects: 19


Mojang Specifications


« Reply #16 - Posted 2009-05-15 09:24:22 »

An applet can connect back only to [..] 'the web' port 80.

Are you sure? When did this change?

Play Minecraft!
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 613
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #17 - Posted 2009-05-15 09:43:28 »

Try to replace:
s = new ServerSocket(4444);

With:
int port = 4444;
int backlog = 50;
String host = "localhost";
new ServerSocket(port, backlog, InetAddress.getByName(host));



The first line will bind to your router/switch (probably 192.168.x.x or 10.0.0.x, not 127.0.0.1)

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Mr_Light

Senior Member




shiny.


« Reply #18 - Posted 2009-05-15 17:46:16 »

given the code i posted above and what you just said mr.light shouldn't my program run?
There's a difference between getting a program to run and making it work. Wink

Anyway, try actually doing something in that catch block, as that probably leads you to the solution quicker.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline neoskunk

Junior Member





« Reply #19 - Posted 2009-05-15 19:25:25 »

i tried what you suggested Riven and it still does the same thing.  the code i posted used to work and now it doesn't even though i didn't change anything.  however, i did change my computer from xp to vista....   would that maybe have something to do with it?
Offline Mr_Light

Senior Member




shiny.


« Reply #20 - Posted 2009-05-15 19:30:04 »

running any firewalls?

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline Wildern

Junior Member





« Reply #21 - Posted 2009-05-15 23:52:17 »

I had a Vista issue that's sounds very similar.

See relevant thread here http://www.java-gaming.org/topics/getting-odd-security-exception-in-my-applet/19960/msg/159489/view.html#msg159489

When you create the socket, don't include http:// in the host name.
You can have the http:// on XP and it works just fine, but on Vista you get a security exception.

To verify if this is your issue, you could try
1  
new ServerSocket("127.0.0.1",4444)

and then point your browser to
http://127.0.0.1/client.html (or whatever the name of the page holding your applet is)
Offline Mr_Light

Senior Member




shiny.


« Reply #22 - Posted 2009-05-16 00:07:04 »

I'm confused afaik : and / aren't legal characters for a hostname.

"RFCs mandate that a hostname's labels may contain only the ASCII letters 'a' through 'z' (case-insensitive), the digits '0' through '9', and the hyphen. Hostname labels cannot begin or end with a hyphen. No other symbols, punctuation characters, or blank spaces are permitted." http://en.wikipedia.org/wiki/Hostname

I'm also pretty sure
1  
new ServerSocket("127.0.0.1",4444)

corresponds to
http://127.0.0.1:4444/client.html

which if you would enter in your browser will open a tcp connection to 127.0.0.1 and port 4444(if omitted it's 80)

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline neoskunk

Junior Member





« Reply #23 - Posted 2009-05-16 02:21:07 »

ok im not entirely sure but im getting the same exception as in your other thread wildern....

java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:4444 connect, resolve)

this error occurs with

1  
new ServerSocket("127.0.0.1",4444);  and new ServerSocket("localhost",4444);


also something interesting to note is that i get the exact same error regardless of whether or not i run the server application but as i already said the server throws no exceptions thus it should be connected to the correct port and host.

if this is the same sort of problem you had wildren how do i fix it since i do not make reference to http:// in my code?

edit:  yes i have a mcafee firewall and windows defender is running.  i had the same firewall on my xp install and it caused no problems.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 613
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #24 - Posted 2009-05-16 12:11:27 »

As you get the exception from the SecurityManager, there is no way a firewall can cause this.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline neoskunk

Junior Member





« Reply #25 - Posted 2009-05-16 19:28:44 »

yea i didn't think the firewall was the issue.  since i get the same exception regardless of whether or not i run the server program, would the exceptions for not being able to bind to the host and the host not existing be the same?
Offline Wildern

Junior Member





« Reply #26 - Posted 2009-05-18 17:01:47 »

I am not really sure how to help, I will see if I can get the test applet you provided up an running in a VM.
Maybe some more questions will provide a clue.
What webserver are you running, apache?
What browser are you using?
Do you get the same result using a different browser?
What is the URL you enter in the browser?
Offline markmistry

Junior Member





« Reply #27 - Posted 2009-05-18 18:02:54 »

try running them as applications to test them.
i think youll find that you will need to sign the applet or jar to let them do anything that involves i/o.
Im suprised your not getting an i/o port already in use error.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 613
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #28 - Posted 2009-05-18 18:08:17 »

I showed you an applet that successfully connects to it's host and downloads a file. It is not signed.

If everything else fails, just copy everything from my sourcecode, and try to integrate it in your app.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline markmistry

Junior Member





« Reply #29 - Posted 2009-05-18 18:29:50 »

Gonna try and steal your code riven  Cheesy..
will it work also for accesing resources on a different host? or does it have to be signed then probably will wont it ?

hmm stuck please show  Grin

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
   public static void URLReader() {

      try{
         URL kickassip = new URL("http://www.kickassevolution.com/coreservers.html");
         BufferedReader in = new BufferedReader(new InputStreamReader(kickassip.openStream()));

         kickass.regip = in.readLine().toString();
         
         in.close();
   
      }
     
      catch(Exception e){
     
      }
   
    }

I dont think it will work as i have to use this from a remote server  Undecided


Pages: [1] 2
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

theagentd (6 views)
2014-04-24 23:00:44

xsi3rr4x (83 views)
2014-04-15 18:08:23

BurntPizza (75 views)
2014-04-15 03:46:01

UprightPath (86 views)
2014-04-14 17:39:50

UprightPath (69 views)
2014-04-14 17:35:47

Porlus (86 views)
2014-04-14 15:48:38

tom_mai78101 (109 views)
2014-04-10 04:04:31

BurntPizza (169 views)
2014-04-08 23:06:04

tom_mai78101 (265 views)
2014-04-05 13:34:39

trollwarrior1 (216 views)
2014-04-04 12:06:45
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!