设置基本的Twisted Reactor(Set up basic Twisted Reactor)
我很擅长使用Twisted。 我在.py中设置了一个协议,它运行得很好。 问题是,目前要测试它我必须ssh到我的服务器并运行它。 我想让它作为服务/服务器运行,所以它总是服务我的协议。 我在扭曲的网站上读到了一些关于.tac文件的内容,但我不知道如何将其与我编写的协议文件联系起来。
我所拥有的只是一个简单的基于套接字的iPhone应用程序,它将消息发送到反应器并接收消息。
我想在服务器启动时启动它。 就像一个apache服务器工作。
谢谢你的帮助。
I am very new to using Twisted. I have set up a protocol in a .py and it works perfectly. The thing is that currently to test it I have to ssh into my server and run it. I would like to have it running as a service/server so it is always serving my protocol. I read on the twisted site something about .tac files but I'm not sure how to tie that in with the protocol file I've written.
All I have is a simple socket based iPhone app that sends messages to the reactor and receives messages back.
I would like this to start up when the server boots. Much like an apache server works.
Thanks for your help.
原文:https://stackoverflow.com/questions/8570403
最满意答案
你当前的目录不是你想象的那样,所以“../”未能按你认为的那样去。 尝试这样的事情:
db = require('path').join(__dirname,'../db.js')
the root directory is where you start the app by calling node on that js file.
if the file is on the root of that file, you need to write
var db = require('./db'); // same file as yours.
using
'../'
will go to the parent folder and look there.using
'db'
directly will look in the node_modules for the db module.
相关问答
更多-
更改a.js导出变量: exports.test = "Hello World"; 并将require('./a.js')的返回值分配给变量: var a = require('./a.js'); console.log(a.test); 您经常看到并可能使用的另一种模式是将一些东西(一个对象,函数)分配给module.exports中的module.exports对象,如下所示: module.exports = { big: "string" }; Change a.js to export th ...
-
假设您通过mocha测试,您必须使用mocha命令而不是node可执行文件运行测试。 所以如果你还没有,请确保你做npm install mocha -g 。 然后在项目的根目录中运行mocha 。 Assuming you are testing via mocha, you have to run your tests using the mocha command instead of the node executable. So if you haven't already, make sure ...
-
评论不会以显着的方式影响代码的性能。 无论是在客户端还是在服务器端。 客户端会发生什么情况:如果您将JavaScript添加到注释中,那么这些代码仍然由浏览器下载,而不会为用户带来额外的好处。 Comments do not affect code performance in a significant way. Neither in the in client nor in the server. What happens in the client is that if you're includin ...
-
你当前的目录不是你想象的那样,所以“../”未能按你认为的那样去。 尝试这样的事情: db = require('path').join(__dirname,'../db.js') 以下是__dirname和path的信息。 the root directory is where you start the app by calling node on that js file. if the file is on the root of that file, you need to write var ...
-
您很可能安装了Microsoft HPC Pack ,它具有自己的node.exe ,并且正在挑选此可执行文件。 如果您没有使用它,我建议删除它以减少混乱。 否则,如果您确定已从node.js网站 (例如Windows安装程序)安装了node.js,请确保%PATH%中的node.js路径位于Microsoft HPC Pack的node.exe路径之前确保它选择“正确”的node.exe。 Most likely you have the Microsoft HPC Pack installed, whi ...
-
您需要确保它封装在$(document).ready()处理程序中或者在DOM加载之后 $(document).ready(function () { $(window).scroll(function () { if ($(window).scrollTop() > 164) { $("ticky-nav").show(); } else { $("ticky-nav").hide(); } } ...
-
嗯,实际上有一种获取当前 script ,例如: // external script (function () { var scripts = document.getElementsByTagName('script'), currentScript = scripts[scripts.length - 1], scriptUrl = currentScript; alert("scriptUrl: " + scriptUrl); })(); 上面的工作原理是因为在执 ...
-
imagesLoaded在您传递给ready的匿名函数的范围内定义。 它不是全局的,不能从其他脚本调用。 将其移出匿名函数以使其成为全局函数。 imagesLoaded is defined in the scope of the anonymous function you pass to ready. It is not a global and cannot be called from other scripts. Move it outside of the anonymous function ...
-
如何在外部file.js中将参数从PHP发送到Backbone(How to send parameters from PHP to Backbone in external file.js)[2023-01-27]
所以你基本上有两个选择: 你可以PHP-ify你的JS文件。 我不是PHP专家,所以我不能告诉你如何做到这一点的细节,但实际上有一些设置可以修改,告诉PHP处理你的* .js文件。 如果你这样做,那么你可以将你想要的任何PHP逻辑粘贴到app.js (或任何其他JS文件)。 然而,这种方法强烈地耦合了你的PHP和你的JS代码,这通常被认为是一个坏主意(出于同样的原因,大量混合你的PHP和HTML被认为是不好的做法)。 因此,我建议...... 您可以将PHP部分编写到PHP页面上的变量中,然后在JS文件中引 ... -
尝试: for(var i = 0; i < routes.length; i++){ require('./Routes/' + routes[i])(app); } Try : for(var i = 0; i < routes.length; i++){ require('./Routes/' + routes[i])(app); }