简体   繁体   English

远程服务器上的Node.js:未定义io

[英]Node.js on a remote server: io is not defined

I'm building an application that links to a node.js hosted on my home computer (78.233.79.103:8000) 我正在构建一个链接到家用计算机上托管的node.js的应用程序(78.233.79.103:8000)

The server is properly istalled (if you go to the addres I gave you'll se the socket.io works) If I run the server in localhost with 服务器已正确安装(如果您转到我给的地址,则socket.io会正常工作)如果我在本地主机上运行服务器

node server.js

all is good, the application works 一切都很好,应用程序可以正常工作

Then when I run the application on my other pc or on my iPad (I wrapped it with phoneGap so it's just a web app included in a native iOS app), trying to connect the io on 78.233.79.103:8000 i got the console log: 然后,当我在另一台PC或iPad上运行该应用程序时(我用phoneGap包装了它,因此它只是本机iOS应用程序中包含的一个Web应用程序),尝试在78.233.79.103:8000上连接io,我得到了控制台日志:

io is not defined

here is my sourcecode: https://github.com/synbioz/puissance4 这是我的源代码: https : //github.com/synbioz/puissance4

look for the server.js 寻找server.js

I know I only call io = require('socket.io').listen(PORT); 我知道我只叫io = require('socket.io')。listen(PORT); but kwnow also I should create something like: 但我也应该创建类似的内容:

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(8000, '78.233.79.103');

that actually doesn't works 那实际上是行不通的

Any idea? 任何想法?

probably because .listen() doesn't return this . 可能是因为.listen()不返回this

try writing them in separate lines. 尝试将它们写在单独的行中。

var io = require('socket.io');
io.listen(PORT);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM