我在 socket.io 中使用 nestjs 后端和 Vuejs 前端,需要查看用户是否“isAlive”。
我试过 ping 服务器端和 pong 客户端,但服务器端什么都不做......
服务器端(nest.js)
@WebSocketGateway({
pingTimeout: 100
})
export class LockGateway {
@SubscribeMessage('ping')
ping(socket: Socket, data: any) {
console.log(`Ping with ${data.toString()}`);
socket.emit('pong', (response) => {
console.log(`Response from client side : ${response.toString()}`);
});
}
}
客户端(vuejs / ts)
this.socket.on('pong', () => {
console.log('PONG I m alive');
this.socket.emit('ping', 'I m alive');
});
在客户端,我在 pong 中拥有所有 console.log,但在服务器端,什么都没有:/
红糖糍粑
qq_遁去的一_1
相关分类