WebSocket connection failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

112,063

Solution 1

Chrome doesn't allow unsecure websocket (ws) connections to localhost (only wss, so you should setup a TLS certificate for your local web/websocket server). However the same should work fine with Firefox.

Solution 2

You need to use ws://yourIp:9090/, where yourIP is like 192.168.?.?.

Solution 3

try to change the port to 8080

const ws = new WebSocket('ws://localhost:8080/chat')

Solution 4

Port 9090 is used by reactotron. Probably you are using it in your project and your app cannot connect with reactotron because it is closed. Just open reactotron and the error will disappear.

Solution 5

Usually WebRTC requires a secure connection (that is https). The error you have got is due to TLS/SSL certificates occupied, may be they are not properly configured in your project. Provide a valid TLS/SSL certificate and also configure it correctly in project, then it will work without the above error.

Share:
112,063
Hafsa
Author by

Hafsa

Updated on October 01, 2021

Comments

  • Hafsa
    Hafsa over 2 years

    I am new to WebRTC and WebSockets and was following this tutorial to create a WebRTC demo project, but I am unable to create a WebSocket connection. I have followed the same steps as mentioned in the project. His project is running on port 8080 and he mentioned ws://localhost:9090. My project is running on port 8081, but I copied his URL ws://localhost:9090 because I didn't know the significance of 9090 and I received this error and my server is node.js. i changed local host to 8081 as well but then i am getting hand shake error.

    WebSocket connection to 'ws://localhost:9090/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED.

  • Nick stands with Ukraine
    Nick stands with Ukraine over 6 years
    This is a borderline link-only answer. You should expand your answer to include as much information here, and use the link only for reference.
  • Esqarrouth
    Esqarrouth almost 4 years
    What is the significance of chat here? Wouldn't that be invalid port?
  • Shantilal Suthar
    Shantilal Suthar almost 3 years
    I tried to run websocket with the url var wsUri = "ws://localhost:55195/" and it says WebSocket connection to 'ws://localhost:55195/' failed: Have been looking to fix this issue since 4 days, still not getting what is wrong with the code? any suggestion to fix this problem will be highly appreciated. let me know if anyone need to see the code as well! thanks in advance.
  • Dorian
    Dorian over 2 years
    it's the path in the wesockets server server url, e.g. /chat for your chat messages, /matches for your tinder matches, etc. probably for some scaling concerns