Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

I try to connect with socket to my server. My server is running server socket with Rachet on port 8080. I try to run this code:

<script>         try{     conn = new WebSocket('wss://localhost:8080');   conn.onclose = function (e) {         //checkUser(); }  conn.onopen = function(e)  {     console.log("test"); };      }catch (error) {     console.log(error); }    </script> 

But I get this error:

WebSocket connection to 'wss://localhost:8080/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED 

When I try to connect from my linux shell I get this:

root@(none):~# telnet localhost 8080 Trying ::1... Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. 
like image 692
dasdasd Avatar asked Mar 01 '15 22:03

dasdasd


People also ask

What is Net :: Err_connection_refused?

Result: net::ERR_CONNECTION_REFUSEDIt indicates that no existing connection to the server was available for use by this request and the browser is creating a new TCP connection to the specified IP address. The request returned a HTTP status code failure or caused an internal browser error.

Why is 127.0 0.1 refused to connect?

Your client is trying to connect to the local loopback IP 127.0. 0.1 , which will work only if the server is running on the same device as the client. That is why you are getting "connection refused" - there is no server listening locally at 127.0. 0.1:9998 .


2 Answers

CONNECTION_REFUSED is standard when the port is closed, but it could be rejected because SSL is failing authentication (one of a billion reasons). Did you configure SSL with Ratchet? (Apache is bypassed) Did you try without SSL in JavaScript?

I don't think Ratchet has built-in support for SSL. But even if it does you'll want to try the ws:// protocol first; it's a lot simpler, easier to debug, and closer to telnet. Chrome or the socket service may also be generating the REFUSED error if the service doesn't support SSL (because you explicitly requested SSL).

However the refused message is likely a server side problem, (usually port closed).

like image 118
btraas Avatar answered Sep 16 '22 13:09

btraas


Firstly, I would try a non-secure websocket connection. So remove one of the s's from the connection address:

conn = new WebSocket('ws://localhost:8080'); 

If that doesn't work, then the next thing I would check is your server's firewall settings. You need to open port 8080 both in TCP_IN and TCP_OUT.

like image 24
Nate Avatar answered Sep 17 '22 13:09

Nate