I want to set up a chat site on my FreeBSD, but when I access it, I get an error in the developer tools console, and the error code is as follows:
socket.io.js:1407 GET http://jzr2011.serv00.net/socket.io/?EIO=4&transport=polling&t=P4sBY9q 404 (Not Found)
The source code of the webpage is as follows:
server.js:
index.html:
Thank you all for your help!
socket.io.js:1407 GET http://jzr2011.serv00.net/socket.io/?EIO=4&transport=polling&t=P4sBY9q 404 (Not Found)
The source code of the webpage is as follows:
server.js:
Code:
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var usocket = [];
io.listen(38366)
app.get('/', function(req, res){
res.sendFile(__dirname + '/chat.html');
});
io.on('connection', function(socket){
console.log('a user connected')
socket.on("join", function (name) {
usocket[name] = socket
io.emit("join", name)
})
socket.on("message", function (msg) {
io.emit("message", msg)
})
});
http.listen(39156, function() {
console.log('listening on *:39156');
});
index.html:
Code:
<!doctype html>
<html>
<head>
<title>chat</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: '微软雅黑'
}
#container {
width: 100%;
height: 1700px;
background: #eee;
position: relative;
box-shadow: 40px 40px 110px #777;
}
.header {
background: #25421ab0;
height: 80px;
color: #fff;
line-height: 68px;
font-size: 40px;
padding: 0 20px;
}
body {
width: 100%;
background: #eee;
position: relative;
font: 60px;
}
form {
background: #000;
position: fixed;
bottom: 0;
width: 100%;
}
form input {
border: 0;
width: 80%;
font-size: 40px;
}
form button {
width: 20%;
background: rgb(130, 224, 255);
border: none;
font-size: 40px;
}
#messages {
list-style-type: none;
margin: 0;
padding: 0;
font-size: 40px;
}
#messages li {
padding: 5px 10px;
font-size: 40px;
}
#messages li:nth-child(odd) {
background: #eee;
}
</style>
<script src="[URL]http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js[/URL]"></script>
</head>
<body>
<div class="header">
<span style="float: left;">chat</span>
<!--<span style="float: right;">14:21</span>-->
</div>
<ul id="messages"></ul>
<form action="">
<input id="m" placeholder="speak some thing to talt..." autocomplete="off" /><button>send</button>
</form>
</body>
<script src="/node_modules/socket.io/client-dist/socket.io.js"></script>
<script>
var name = prompt("what's your name?");
var socket = io()
socket.emit("join", name)
document.title = name + "chat gound"
socket.on("join", function (user) {
addLine(user + " join")
})
socket.on("message", function (msg) {
addLine(msg)
})
//当发送按钮被点击时
$('form').submit(function () {
var msg = $("#m").val()
socket.emit("message", msg)
$("#m").val("")
return false
})
function addLine(msg) {
$('#messages').append($('<li>').text(msg));
}
</script>
</html>