[英]Running /socket.io/socket.io.js using a public IP
So, I'm trying to run my Node.js on my private server. 因此,我正在尝试在私有服务器上运行Node.js。 Now the thing is, I've created a chat program, which works great and all when I run it on a local network.
现在的事情是,我创建了一个聊天程序,当我在本地网络上运行该程序时,该程序非常有用。
Now, when I change the IP's to my public IP it won't load the /socket.io/socket.io.js
file. 现在,当我将IP更改为我的公共IP时,将不会加载
/socket.io/socket.io.js
文件。 It says net::ERR_CONNECTION_TIMED_OUT
它说
net::ERR_CONNECTION_TIMED_OUT
The parts of the code where I'm connecting are: 我连接的代码部分是:
Server.js: Server.js:
var mongo = require('mongodb').MongoClient,
client = require('socket.io').listen(8080).sockets;
console.log('info - socket.io started');
mongo.connect('mongodb://127.0.0.1/chat', function(err, db) {
if(err) throw err;
Index.html: Index.html:
<script src="http://94.211.125.196:8080/socket.io/socket.io.js"></script>
<script>
// Try connection
try {
var socket = io.connect('http://94.211.125.196:8080');
} catch(e) {
// Set status to warn user
}
</script>
I do have the required ports port forwarded to my server ( 8080
& 27017
) 我确实将所需的端口端口转发到了我的服务器(
8080
和27017
)
You're not hosting the socket.io.js
file. 您没有托管
socket.io.js
文件。 You need to include the js file from somewhere else or host it by starting a httpServer in your node script. 您需要从其他位置包含js文件,或者通过在节点脚本中启动httpServer来托管它。 Try using the socket.io cdn:
尝试使用socket.io CDN:
<script src="https://cdn.socket.io/socket.io-1.3.5.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.