简体   繁体   中英

Use public IP address for java application

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");
            }
        });
    }
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM