socket.io-android-chat icon indicating copy to clipboard operation
socket.io-android-chat copied to clipboard

Clear buffer after connect to server

Open pishguy opened this issue 8 years ago • 6 comments

how can i clear buffer after connect to server, when i disconnected from server and trying to emmit data, that buffered and after connect to server, this library send all buffered, this code, resolve my problem on web client

mySocket.on('connect', function () {
    mySocket.sendBuffer=[]
    console.log('Connected!');
});

pishguy avatar May 22 '17 08:05 pishguy

+1 we need a way for clean the buffer, in my case the var mySocket.sendBuffer is private, i cant modify it.

improve-ar avatar Oct 03 '17 13:10 improve-ar

private void onconnect() { this.connected = true; this.emit(EVENT_CONNECT); this.emitBuffered(); }

I see on reconnect, you will send receiveBuffer. How i can to clear receiveBuffer, because i don't want to send anything while socket reconnect? Thanks pro

hoangnamit1991 avatar Apr 19 '18 10:04 hoangnamit1991

I resolve it adding ID to every "package" i send, and the server reject it if exist

improve-ar avatar Apr 19 '18 12:04 improve-ar

@juanmanuelarze could you take a sample?

pishguy avatar Apr 19 '18 15:04 pishguy

just put an extra key with the ID (is a random string) in the object you emit and do the check in server

improve-ar avatar Apr 19 '18 15:04 improve-ar

@juanmanuelarze could you take a sample?

+1 Need for clear buffer like nodejs socket.io-client.

When sending data with the "emit" command, it is possible that before the "on event" command runs, there will be a data buffer pending on the Android device side and make data "on event" to be executed twice when "socket on_connect" is called. So we want to be able to call "clear buffer" or clear the pending buffer if needed

YovanggaAnandhika avatar Mar 19 '23 22:03 YovanggaAnandhika