socket.io 搭建了websocket,但是我用原生js却connect不上?

index.js

/**
 * Created by mh on 2016/9/15.
 */
var path = require('path');
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);

app.use(express.static('public'));

app.get('/', function(req, res){
    res.sendFile(__dirname + '/index.html');
});



io.on('connection', function(socket){
    console.log('a user connected');
    socket.on('chat message', function(msg){
        socket.broadcast.emit('chat message' ,msg);
    });
});

http.listen(3000, function() {
    console.log('listening on *:3000');
});

结果:

这是连接代码:

查看回复