作为一名C ++ / C#程序员我是Javascript中的新手(不是我的选择,我大学的蹩脚课程)而且我要开发一个小程序,使用vert.x创建孩子,这将计算文本中包含的单词文件。
我想使用点对点方法。
这是我实际为父母做的事情:
var vertx = require ('vertx');
var console = require('vertx/console');
var container = require('vertx/container')
var eb = require('vertx/event_bus');
vertx.fileSystem.OPEN_READ = 1
vertx.fileSystem.OPEN_WRITE = 2
vertx.fileSystem.CREATE_NEW = 4
vertx.createHttpServer().requestHandler(function(req)
{
vertx.fileSystem.readFile('dataset.txt', function(err, res)
{
if (!err)
{
var str = res.toString();
var myarray = str.split(' ');
for (var i = 0; i < myarray.length; i++)
{
myarray[i] = myarray[i].replace(".", "");
myarray[i] = myarray[i].replace(",", "");
}
var config = {adresse: 'boap'}
var id = container.deployVerticle('child.js', config, 1);
var reply;
vertx.setperiodic(1000, function sendmessage()
{
eb.send('lama', 'ping!', function(reply)
{
console.log("received reply: " + reply);
});
});
}
});
}).listen(1234, 'localhost');
这是孩子:
var eb = require('vertx/event_bus');
var console = require('vertx/console');
var container = require('vertx/container')
var log = container.logger;
log.info("in child.js, config is " + container.config.adresse);
eb.registerHandler('lama', function(message, replier) {
console.log('Received message ' + message);
// Now reply to it
replier('pong!');
});
问题是当我启动它时出现以下错误:
Succeeded in deploying verticle
Exception in JavaScript verticle:
TypeError: Cannot find function setperiodic in object [object Object].
at file:/C:/Users/3wic/Documents/vert.x-2.1M2/bin/lama.js:30 (anonymous)
at file:/C:/Users/3wic/Documents/vert.x-2.1M2/sys-mods/io.vertx~lang-rhi
no~2.0.0-final/vertx/file_system.js:47 (anonymous)
in child.js, config is boap
任何人都知道为什么无法识别此功能?
答案 0 :(得分:0)
由tim_yates回答,检查评论