I originally posted this question on stackoveflow but was advised that it would be more suited to this site.
I am trying to access a Jetty Server deployed on one machine from another machine outside LAN but it's not working. I've read this thread and followed the advise offered by @Joakim Erdfelt however it did not work. My code is below:
Server server = new Server();
// HTTP connector
ServerConnector serverConnector = new ServerConnector(server, 1, 1);
serverConnector.setHost("0.0.0.0"); <-
serverConnector.setPort(8080);
serverConnector.setIdleTimeout(30000);
// Set the connector
server.addConnector(serverConnector);
I tried accessing the server from another remote server with the following code:
String postUrl = "http://" + myIP + ":8080"; // myIP is set to the public IP address of Jetty Server
System.out.println("Post URL: " + postUrl);
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(120 * 1000).build();
try (CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();) {
HttpPost httpPostRequest = new HttpPost(postUrl);
...
However, this throws the following exception:
HttpPostConnectException: Connect to 123.4.56.78:8080.. failed: Connection refused: connect
What is causing this error? I allowed Firewall access when prompted so I don't think it is a Firewall issue. The port 8080
is also not being used for any other process. I tried multiple ports to no avail.
Thanks