简体   繁体   中英

What is the difference between net.connect and net.createConnection in node.js?

I was reading the documentation from the net module in Node.js and I can't see any difference between the methods net.connect and net.createConnection .

Are they exactly the same or is there is some difference?

There's no difference. Here's an extract from the source code :

exports.connect = exports.createConnection = function() {

I agree the documentation isn't clear on that point.

The are exactly the same, just a different name, form the sourced code

net.createConnection() creates a net.Socket object and immediately calls net.Socket.connect() on it.

And also from the source code on line 62 of the Net module.

exports.connect = exports.createConnection = function() {
  stuff
};

Why they did this, I don't know. Just pick the naming convention that you prefer and off you go :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM