Ktor project localhost:8080 refuses to connect - java

I was working on a ktor project and everything was working fine. I started the server and it was working fine on port 8080 but now for some reason suddenly it stopped working. I killed the task and tried everything, I'm not sure what's wrong. I tried to reinstall IntelliJ Idea and I'm still facing the same issue. I tried using 127.0.0.1
, 0.0.0.0
, localhost but none of them work idk what to do. I've wasted like 2 hours on this thing. I've tried changing port, blocking firewall and antivirus.

change 127.0.0.1(localhost) to your private ip like 172.30.1.59 if you use wifi. if you use fixed ip then use it. i have same problem, but solve it with this. Nice!
cmd -> ipconfig -> use ip address

I usually had the same issue using Ktor and it is frustrating. Then I am gonna post the following possible fixes that you should try in order and reading the steps. I am going to consider that you are running a WebSocket server and a WebSocket client for your Android app in a unique computer.
You are running the server side and the client using the same ip and
it should not work, because the client can not connect to the
server. When I am testing a project that requires server-side and
client-side I use my computer to run the Android app and the laptop
to run the server side. If this is not your case, then, do
not pay attention.
In the client-side, when you create the instance of the HttpClient,
do you pass any value to the client as engine or you simply go
directly with lambda? From my experience, when I create the
HttpClient instance, only works these two following first ones:
val client = HttpClient {
install(WebSockets)
}
or
val client = HttpClient(CIO){
install(WebSockets)
}
The engine that doesn't work for me is:
val client = HttpClient(OkHttp) {
install(WebSockets)
}
Finally, when you create the WebSocket using the past client
instance, you should use
client.ws(
HttpMethod.Get,
"localhost",
8080,
"/"
)
{
//Client code
}
and not client.wss. That is because in local connection, your client
do not connect using TLS security and it will throw an exception. If
you're deploying your server-side in a hosting that has TLS security
as Heroku, then you can use the wss one, because the client-side
will connect using TLS certificate.
Hope that my response can help. Good luck!

I had the same problem and it turned out that it was because I had the HttpsRedirect and HSTS plugins installed. Due to this it refused to handle the http request and since I don't have any certificate for localhost or my local IP it didn't work.
Disabling these two plugins when running locally makes things work for me.

Related

I can't connect to my dropwizard application remotely

I am able to succesfully use my dropwizard application when accessing with localhosts, but it doesnt work when I access with a different machine. Is there something you need to do make your web application respond to hosts besides localhosts?
I know with flask you must run with the flask run --host=0.0.0.0 is there a setting in the config file which controls this.
If you connect from the same network you´ll probably have an windows firewall issue (if you run on windows) or any other firewall depending on the OS.
You´ll have to allow inbound connections for the specific application on or port 80/443 TCP.
If you´re trying to connect from another network then it probably still is the above but you also have to setup port-forwarding to the machine running your application.
If it´s HTTP, probably port 80. If HTTPS then probably 443, for any other protocol you have to find out the correct port.
Since it´s dropwizard it´s probably HTTP/HTTPS, depending if it has to be secure (definatly recommended for REST APIs)

Tomcat, site can’t be reached

I am using Amazon EC2, on my VM installed Tomcat 8.5.8. Everything was ok, but recently i realized that my webapp not working. I didn't change anything, but everytime i try to open it - i get 'This site can’t be reached' error.
I have custom Security Groups rules for the HTTP traffic (port 80) and also HTTPS traffic (port 443), both on TCP. As i said, everything was ok, but now it's not working :(
here my logs: https://pastebin.com/hkDZ5HtM
my website address: http://antilamer.tk/
Problem was in Tomcat, i've reinstalled it and now it works.

WebSocket connection delay without localhost

I'm developing a WebApp in a company using WebSockets. It's currently in a basic "client sends message, server responds"-state and works just as it's supposed to work... under localhost that is.
I'm using a Tomcat 7 and Netbeans to deploy the app. So basically I reach it under
localhost:8080/WebApp
and the WebSocket itself is referenced as
var ws = new WebSocket("ws://localhost:8080/WebSocketTest/WsSendTest");
If I now change the "localhost" to my Network IP I can still reach the Website, but the functionality seems broken. I have a "ping" button that sends a ping-msg to the server. If I rapidly click on that the functionality seems to be restored. But after F5-ing it's broken again.
It only seem to happen when I change the ws:// path to my IP.
Weird thing is, the onOpen()-method is implemented in a way, that it logs the session-ID of any client connecting to the WebSocket and it recognizes the connection immediately. Just the rest seems to "lag" or "block"?
I will end up having to use the IP since other ppl in the network can't rech the ws:// if it's set on localhost in the webpage.
Can anyone relate?

Getting java.net.ConnectException : Connection refused

I looked for solutions on SO for this but none of them seem to apply to my case. So here goes:
I have an application that needs to make a service call to a third party domain. I am using jersey client to make this service call. The code for making this call is
ClientResponse resp = resourceWithParams.
header("Authorization", getAccessKeyId() + ":" +
hmacSha1.toUpperCase()).
post(ClientResponse.class,"");
where resourceWithParams is the jersey web resource. Note that even though its is a POST, the web service is expecting a query string and empty body. It might be questionable design but that is what we have to work with.
This setup is working just fine on my local machine as well as on our preprod server. However on our production servers it gives an exception:
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused
There are a couple of points below that might be helpful in pointing me in the right direction:
1) We get a valid response when we use curl on the prod server command line to send a request to the web service so seems like there are no firewall issues. This is happening only when we try it through the web application, i.e. through the java code using jersey client.
2) There are no proxies set up on the prod servers
3) Works fine from localhost.
4) The Rest webservice uses https and the correct certificates are installed on our server which is proved by the fact that curling the webservice on prod works fine.
Any ideas on what the issue might be and where we should start looking?
EDIT:
As mentioned we were using https to connect to the webservice. If we use http instead, it does seem to be working.
I suggest you set up a tcpdump session to see where the connection refused is coming from. In particular, see what the source IP and destination IP addresses are, for both the successful connections and the unsuccessful ones.
There are two possibilities the above is designed to test for:
You say you're not using proxy servers, but Java actually has a separate proxy configuration from the rest of the system, so it may be that your Java is configured to use a non-functional proxy server.
Your Java system could be sending requests using a different source IP address to the one that your curl is using.

URL Rewrite IIS and Glassfish from port 8080 to 80

I'm running a glassfish server that handles all jsp and servlets.
Now there is a way to get it working so that you can run IIS on port 80 and glassfish on port 8080, now the problem is:
When i request http://localhost/myWebApplication it should rewrite the url and use http://localhost:8080/myWebApplication
Basically I make a request to IIS, but the response I get back must be from Glassfish.
When I request the url with port 8080 it works, because its getting it from Glassfish, but i need to go through IIS to Glassfish.
Here is a website that explains it all: http://jstoup.wordpress.com/2012/04/25/how-to-integrate-glassfish-with-iis/
but I still can't get it working.
I have got no idea how my url rewrite rules must be set up.
This is James from the blog you referenced. If you haven't gotten this working you may have to enable your server farm as a proxy. If you select your web farm there should be a proxy config in the center console. All you should have to do is turn that on and you should be good to go. Let me know if you've got any problems

Categories