C节点本机扩展调用方法两次
所以我对C相当陌生,并且在简单的Node Native扩展上工作。
这里是我的扩展名为helloworld.c的代码
Handle<Value> Method(const Arguments& args) { printf(":%s:\n", "Calling Method"); //SendByte(bdrate,'1'); HandleScope scope; if(toggleLight()==0){ printf(":%s:\n", "Turning On"); return scope.Close(String::New("Turned On")); } else{ printf(":%s:\n", "Turning Off"); return scope.Close(String::New("Turned Off")); } } void init(Handle<Object> target) { printf(":%s:\n", "Init"); target->Set(String::NewSymbol("hello"), FunctionTemplate::New(Method)->GetFunction()); } NODE_MODULE(helloworld, init)
我通过下面的Node.js类消耗以前的…
var addon = require('./build/Release/helloworld'); var http = require("http"); http.createServer(function(request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.write(addon.hello()); response.end(); }).listen(8888);
当我打电话给我的网站时,我在terminal上看到以下内容
~/Desktop/hellonode$ node testnode :Init: :Calling Method: :Turning Off: :Calling Method: :Turning On:
为什么它似乎在调用这个方法两次? 我相信答案是显而易见的,但我看不到它。
这是重复的。 这不是你的扩展中的错误,这是你的HTTP代码中的一个问题。
看到:
- 简单的http服务器
- node.js页面刷新调用资源两次?
基本上,您的浏览器正在请求两个url/
和/favicon.ico
,而且由于您没有检查url,因此它会在两个请求上运行您的扩展程序代码。
- 在Unity中encryption,在Node.js中解密
- 试图在网站上获取歌曲列表不起作用
- 如何从node-gyp定位'imqi.hpp'
- 我如何成功链接本地Node插件中的Flex,Bison和Node.js?
- Nodejs Addon – 将正则expression式string传递给C ++
- node.js webserver和C ++游戏服务器
- 在运行JS函数时,如何在c#中的Edgejs中获取错误文本?
- 如何传递Local <Function>作为参数?
- 在Asp.Net MVC应用程序的VirtualDirectory中使用IISNode在IIS内托pipeSocket.IO + ExpressJS应用程序