I am using ws with Electron for making a desktop app. I have a WebSocket server which runs in the app, but the problem is that I can't get the IP address of that server. The IP address I'm looking for is that of the device which is listed under ipv4 of the ipconfig in CMD since I'm using Windows 11. The server.address() only returns "::" for the IP address and I need it instead saying "192.168.0.41".
My code goes like this:
wss = new WebSocket.Server({ port: 6000 })
return wss.address() // returns "::" for address
Now on another post someone responded saying that .address() should be called after setting up the server. Well I tried it by making a new Node.js server and I got the same results for the address from the code below.
const net = require("node:net")
const s = net.createServer((socket) => {})
s.listen(() => {
console.log("opened server on: ", s.address()) // returns "::" for address
})
Now the result I'm looking for is in the following screenshot.
Via Active questions tagged javascript - Stack Overflow https://ift.tt/Lsq4CA9
Comments
Post a Comment