尽管遵循了此视频的确切说明:https://www.youtube.com/watch?v=pNKNYLv2BpQ并在必要时更改了详细信息(例如,我使用localhost:8888反对3000),无论我尝试什么,我都会收到错误消息。我变得非常沮丧,因为我不能为我的生活找出错误的地方。
我目前收到错误消息GET http://localhost:8888/socket.io/1/?t=1462670368869 404 (Not Found)
经过一场不断发生错误的大规模挣扎,因为它无法找到“socket.io.js”。文件。任何人都可以对这个毁灭性的神秘主题有所了解吗?
HTML:
<html>
<head>
<title>Chat with socket.io and node.js</title>
<style>
#chat{
height:500px;
}
</style>
</head>
<body>
<div id="chat"></div>
<form id="send-message">
<input size="35" id="message"></input>
<input type="submit"></input>
</form>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="socket.io.js"></script>
<script>
jQuery(function($){
var socket = io.connect();
var $messageForm = $('#send-message');
var $messageBox = $('#message');
var $chat = $('#chat');
$messageForm.submit(function(e){
e.preventDefault();
socket.emit('send message', $messageBox.val());
$messageBox.val('');
});
socket.on('new message', function(data){
$chat.append(data + "<br/>");
});
});
</script>
</body>
</html>
JavaScript的:
var express = require('express');
app = express();
server = require('http').createServer(app);
io = require('socket.io').listen(server);
server.listen(8888);
app.get('/', function(req, res){
res.sendfile(__dirname + '/index.html');
});
io.sockets.on('connection', function(socket){
socket.on('send message', function(data){
io.sockets.emit('new message', data);
});
});
JSON:
{
"name": "chat",
"version": "0.0.1",
"private": "true",
"dependencies": {
"express": "^4.10.2",
"socket.io": "^0.9.16"
}
}