Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Node.js with IPv6?

Tags:

node.js

ipv6

Basically, I'd like to know how can I change my server.js code in order for it to work with IPv6? I read somewhere that you only need to add your IPv6 address right next to the line where it says "listen(80)" which would make it look something like this "listen (80, "IPv6");"

In my code, however, it's a little bit more complicated than that.

Here are the lines of code related to the server:

const 

server = http.createServer(options, app),
                   .
                   .
                   .
var ss=tls.createServer(options, function (box) {
    box.setEncoding('utf8');
                   .
                   .


         ss.listen(8010);
              .
              .


var sockets = require('socket.io').listen(server).of('/el');
                   .
                   .
                   .
if (!module.parent) {
  server.listen(port, function () {
    console.log('Listening', this.address());
  })
}
like image 239
Jesse James Avatar asked Aug 15 '26 13:08

Jesse James


1 Answers

This works here:

http = require('http')

server = http.createServer()
server.listen(8080, '::', function() {
    console.log('listener');
});

Then testing it:

$ telnet ::1 8080
Trying ::1...
Connected to ::1.
Escape character is '^]'.
like image 148
Martin E. Zulliger Avatar answered Aug 18 '26 02:08

Martin E. Zulliger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!