https://github.com/TooTallNat...
伊谢尔伦2017-04-17 14:53:19
It’s strange, why the github address given is a java-websocket project, but the problem appears in the nodejs section. . . I'm dizzy. Anyway, let me tell you based on nodejs! Now yes! ! !
the back-end js:
var express = require('express')
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.use(express.static(__dirname));
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
io.on('connection', function(socket){
console.log('a user connected');
});
http.listen(8888, function() {
console.log('listening on *:8888');
});
the front-end html file
<html>
<body>
<!-- add ur js file here, it server as static content from ur back-end service(express static middleware)-->
<!--<script src='/js/***.js'></script>-->
<script src='/socket.io/socket.io.js'></script>
</body>
</html>
socket.io will automatically capture /socket.io
’s request and return the client file to you.