答案 0 :(得分:-1)
服务器端
var server = http.Server(app);
var io = require('socket.io')(server);
io.on('connection', function (socket){
console.log('Connected');
socket.on('addMe', function(s) {
console.log('Joining Room');
console.log(s);
socket.join(s);
console.log('Joined to Room');
});
socket.on('disconnect', function () {
console.log('Disconnected');
});
});
客户端
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.1.1/socket.io.dev.js"></script>
var socket = io.connect('/');
var roomName = "blah";
socket.emit('addMe', roomName);