websockets/ws

useing localhost in url is not properly working

mathe42 opened this issue · 2 comments

Is there an existing issue for this?

  • I've searched for any related issues and avoided creating a duplicate issue.

Description

We have a websocket running at the current mashine:

I would expect ws://localhost:8000/rpc and ws://127.0.01:8000/rpc would work. But with the following setup:

const WebSocket = require('ws')

const w = new WebSocket('ws://localhost:8000/rpc')
w.addEventListener('open', () => console.log('open'))
w.addEventListener('close', () => console.log('close'))
w.addEventListener('error', (e) => console.log(e))

I get a connect ECONNREFUSED ::1:8000 Error. Changing localhost to 127.0.0.1 works.

ws version

8.8.1

Node.js Version

v18.9.0

System

  System:
    OS: Windows 10 10.0.19044
    CPU: (8) x64 Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz
    Memory: 2.71 GB / 11.98 GB

Expected result

No response

Actual result

No response

Attachments

No response

That is not an issue in ws. It seems your server does not accept connections to ::1:8000 but the DNS resolves localhost to ::1.

Make your sever accept connections to ::1 or tweak the DNS lookup (--dns-result-order=order) to make it return 127.0.0.1.

Oh IPv6! Thanks a lot. This solves this for me!