客户端代码:
<script>
var socket = io.connect('http://127.0.0.1:3000/');
socket.emit('online', {
user: 'hello'
});
socket.on('connect', function() {
console.log(123123);
})
socket.on('error', function(error){
console.log(error);
})
</script>
服务端代码:
const server = http.createServer(app.callback());
const io = new socketIo(server);
io.on('connection', (socket) => {
console.log('a user connected')
socket.on('online', (data) => {
console.log(data);
});
socket.on('disconnect', () => {
console.log('close connect');
});
});
部署: 使用PM2
启动多进程以后, 访问客户端, 出现
错误
文章链接