infitio / flutter_socket_io

Socket IO supprt for flutter. Looking for contributors Swift and Java.
Other
191 stars 113 forks source link

is pulgn support callback #154

Closed hatemragab closed 3 years ago

hatemragab commented 3 years ago

i want to implement something like server code

io.sockets.on('connection', connectionFunc);

function connectionFunc (socket) {
    socket.emit('delete hint', "data for client", callThis);
}

//this function is executed when client calls it
function callThis (dataFromClient){

    console.log("Call back fired: " + dataFromClient);
}

clint code

socket.on('delete hint', function(data, callback) {

        console.log("i received: "+ data);
        // call back will fire only when u the next line runs
        callback("the callThis function on server will run");            

    });

how to perform that in dart callback function not supported in dart version

tiholic commented 3 years ago

@hatemragab if you want to use callbacks, please check out emitWithAck which will return a promise.

You can do something like:

final args = await emitWithAck(....);
console.log('Ack given by server: $args');

-or-

emitWithAck(....).then((args) {
   console.log('callback called with args $args');
});
hatemragab commented 3 years ago

Thanks for replying I already know this case that clint emit what about if server emit and need to confirm that the clint has received

smasinde commented 3 years ago

Thanks for replying I already know this case that clint emit what about if server emit and need to confirm that the clint has received

same thing. the listener you create has an ack callback

hatemragab commented 3 years ago

I have fix it by check if socket.connected true then emit if not not emi

tiholic commented 3 years ago

@hatemragab a new API is added now in V1.0.0

socket.connectSync please check new example in README for more

Feel free to re-open if you still face this issue