node.js错误连接ENOTSOCK

时间:2014-06-30 08:46:54

标签: node.js

当我运行节点脚本时使用node.js我得到此错误不知道我在哪里犯了错误

events.js:72
    throw er; // Unhandled 'error' event
          ^

错误:连接ENOTSOCK     在errnoException(net.js:904:11)     在Object.afterConnect [as oncomplete](net.js:895:19)

这是我用来连接服务器的脚本代码

    var net = require('net');
// createConnection
var connection = net.createConnection({port: 8181, host:'/path/to/local_host/',path:'/Applications/XAMPP/xamppfiles/htdocs'},
// connectListener callback
    function() {
        console.log('connection successful');
});

1 个答案:

答案 0 :(得分:0)

createConnection方法只接受path作为字符串参数,这是unix套接字的路径。

var connection = net.createConnection('/path/to/socket/', function(socket) {
        console.log('connection successful');
});

如果您想要连接到TCP套接字,请从选项对象中删除路径。