0
I am using socket.io and making a server and client in nodejs. The communication between them is working. Server receives notification when client connects and disconnects. I am now needing to send server tasks to the client and store these messages in an array by clients
server.js
io.on( 'connection', ( socket ) =>{
console.log( 'Nova conexão, exibindo o ID desse cliente:', socket.id )
if( socket.id )
{
socket.on('task', ( task ) => {
let arrTask = [];
cron.schedule('*/10 * * * * *', () => {
console.log( task )
})
socket.on('disconnect', () => {
console.log( 'Cliente desconectado' )
})
})
}
})
client js.
socket.on( 'connect', () =>{
console.log( "Cliente conectou" );
socket.emit( 'task', 'Cliente ' + socket.id + ', recebi sua tarefa' );
})
socket.on('msg', (msg) => {
console.log( msg );
});
If anyone can help me I would be grateful. Oh, I’m sorry but I couldn’t get the right code.
@Sorack thanks for editing, I was not getting it. I would know help me on this issue of code?
– user179981