我的节点/回送服务器有一个零星的问题。我的设置如下:Node.js零星的'ECONNREFUSED'错误request.get
编辑:我的节点版本是v4.2.4,我在Windows 10 Professional上运行节点。
客户端:
nw.js客户端遍历本地文件系统,并计算文件的MD5值。
使用
request.post
,客户端发送的文件格式'fileHash: d41d8cd98f00b204e9800998ecf8427e'
服务器的哈希值(这只是一个例子散,我知道这是一个空文件)function checkHash (fileHash){ request.post({ headers: {'content-type' : 'application/x-www-form-urlencoded'}, url: 'http://localhost:3000/api/checkBoths/hashcheck', method: 'POST', form: { fileHash: fileHash } }, function(error, response, body){ if(error) { console.log(error); } else { console.log(response.statusCode, body); } }); }
服务器侧:
节点/环回服务器在运行
localhost:3000
。hashCheck
函数用于读取从客户端发布的数据,并查询用于哈希匹配的MySQL数据库。如果数据库中存在散列,则来自服务器的响应将采用格式
goodResult : true
,如果不存在,则使用goodResult : false
。var request = require('request'); module.exports = function (CheckBoth) { var goodResult; CheckBoth.hashCheck = function (fileHash, cb) { requestGood(fileHash); function requestGood (fileHash) { request.get('http://127.0.0.1:3000/api/Goodhashes/' + fileHash + '/exists', function (error, response, body) { if (!error && response.statusCode == 200) { goodResult = JSON.parse(body).exists; } if (error) { console.error(error); } }); console.log(goodResult); } cb(goodResult); }; CheckBoth.remoteMethod( 'hashCheck', { accepts: {arg: 'fileHash', type: 'string'}, returns: [{arg: 'goodResult', type: 'string'}] } ); };
问题:
服务器可以响应的〜1000个查询之前下出现在整个反应:
{ [Error: connect ECONNREFUSED 127.0.0.1:3000]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 3000 }
我已经试过投入的不同回调服务器代码,但没有任何区别。我想我应该扼杀对服务器的请求,但我不知道如何实现这一点。
任何帮助将不胜感激。
您正在运行哪个版本的节点? – migg
@migg我正在运行v4.2.4 – Oddball
嗯......你的参数被称为'callback',但你正在调用'cb'。也许你正在创建一个memleak,直到服务器拒绝连接? – migg