开发者

Cannot connect to Java Server from external client

开发者 https://www.devze.com 2023-03-03 11:24 出处:网络
I\'m creating a personal tool that serves files through HTTP in Java. For the HTTP Server part I\'m using the com.sun.net.httpserver.HttpServer package.

I'm creating a personal tool that serves files through HTTP in Java. For the HTTP Server part I'm using the com.sun.net.httpserver.HttpServer package. When I connect from my own PC using either localhost or the external hostname, it works, but when I try to connect from an external client to it, it just doesn't. I'd also like to mention that the java default policies file hasn't ever been modified and that I'm behind a router, and that the port is properly forwarded. I tried modifying the policies file but I didn't have any success, although I don't know if the settings were correct or if they got applied, and I read a thread in which there was a similar problem, but using rmi which has been solved by setting the java.rmi.server.hostname system property, but I don't think this is also available in my case because the server uses TCP.

Here's the code that initializes the server:

Settings settings = Controller.getInstance().getModel().getSettings();
            int port = settings.getHTTP_PORT();
            server = HttpServer.create(new InetSocketAddress(port), 20);

            String cachepath = settings.getCachepath();
            if(!cachepath.startsWith("/")) cachepath = "/"+cachepath;
            server.creat开发者_运维百科eContext(cachepath, new HTTPServerHandler());
                            server.start();

If any of you guys can point to what I can do in order to solve this I would really appreciate it.


It seems the server I was trying to connect to was the only case the socket connections were blocked. I asked someone else to connect to it and it worked.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号