【发布时间】:2015-06-16 23:56:24
【问题描述】:
首先,我要感谢您花时间帮助我。
我正在尝试使用 node.js 和 socket.io 实时在线执行 Web 应用程序。 这是我在本地尝试我的应用程序时遇到的问题,但是当我将其推送到 heroku 上时,服务器找不到我的 “herokuApp.heroku.com/socket.io/socket.io.js”
当然,我搜索了很多来解决我的问题,但这里没有任何东西可以解决它。 这是我的文件:
var express = require('express');
var app = express(),
server = require('http').createServer(app),
io = require('socket.io').listen(server),
ent = require('ent'), // Disable HTML caracters (equal htmlentities in PHP)
fs = require('fs');
app.use(express.static(__dirname + '/public_html'));
app.set('port', (process.env.PORT || 5000));
server.listen(5000);
io.sockets.on('connection', function (socket) {
socket.on("newMsg", function(data){
console.log("the client message: " + msg);});
});
app.get('/', function(request, response) {
response.send('Hello World!');
});
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});
在我的 index.html 中
<script src="/socket.io/socket.io.js"></script>
我在推送我的提交时添加了一些信息,例如服务器响应: http://puu.sh/irF05/e1c648c627.png
以及我的文件结构: http://puu.sh/irF8V/8240318ae6.png(上面的代码来自index.js,我不使用server.js)
再次感谢您阅读本文,我对节点或套接字不是很熟悉,如果解决方案简单,请见谅。
【问题讨论】: