在服务器端中:
io.on('connection', function(socket){
socket.on('onTest',function (data) {
console.log(data);
});
socket.emit('onRecive',{data:'test'})
});
需要上面这样才能使用on和emit.
服务端:
let path = require('path');
let express = require('express');
let app = express();
let server = require('http').Server(app);
let io = require('socket.io')(server);.
server.listen(80);
这样socket才能监听80端口
网友评论