-1

I'm building a simple spark application with netbeans Maven. The issue is when I try to access my spark link, I have to put localhost instead of my public IP address. How could I put my public IP address instead of local host or local IP address?

My code is simple, copied from the spark framework website.

public class Main {
    public static void main(String[] args) {
        get("/hello/:name", new Route() {
            public Object handle(Request req, Response res) throws Exception {
                return "Hello sari i'm here"+ req.params(":name");
            }
        });
    }
}
Ron Maupin
  • 6,180
  • 4
  • 29
  • 36
Crystal
  • 13
  • 5
  • It looks like you're trying to get your own ip adress. Not sure this is what you're searching for but this might help you: http://stackoverflow.com/questions/9481865/getting-the-ip-address-of-the-current-machine-using-java , am I right? – Laurent-P Feb 03 '17 at 16:30
  • hello Laurent-P , i'm trying to use my public ip when requesting something from my spark project via url, so instead of using my localhost ip i want to use my public one. – Crystal Feb 03 '17 at 16:31
  • Ok I get it! Requesting with your public IP address is the same as every other website, it will try to do a request to this ip with the port you're asking. But he goes out of your local network so it need to go back in your network, and your pc isn't the front interface of your network. If your port aren't open from the outside, it'll be denied. So you need to open the port from your router. – Laurent-P Feb 03 '17 at 16:37
  • I don't see a hostname or IP address in the code you posted... – Jim Garrison Feb 03 '17 at 16:45

1 Answers1

0

Requesting with your public IP address is the same as every other website, it will try to do a request to this ip with the port you're asking. But he goes out of your local network so it need to go back in this network, and your pc isn't the front interface of it. If your port aren't open from the outside, it'll be denied. So you need to open the port from your router.

Laurent-P
  • 145
  • 1
  • 9