I've been doing this for hours and I do not understand why it's not working for me, besides I've already done systems like chats and I never had a problem, this time is the first time I use Cordova and socket but I can not explain why it happens this.
It turns out that I have 2 open clients, one sends a message and the other receives, this does not work for me, it only works for me if the one who issues the message also listens to receive it.
My code is:
Client issuer:
socket.emit("callDriver", data);
Recipient client:
socket.on("sendToDriver", function(data){
console.log(data);
})
Server:
var io = require('socket.io')(server);
io.on('connection', function(socket){
socket.on('callDriver', function(data){
console.log(data);
socket.emit('sendToDriver', data);
})
})
So if the receiving client waits for the message, it never arrives, but if the same sender is told to listen to "sendToDriver" there the message arrives.
I appreciate your help!