-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
receiving duplicate message #381
Comments
Faced a few of these, never had one that wasn't my fault.
Logging! Set up logging on all events for both client and server to view how things are connecting and disconnecting. I can't answer the question for your use case, because you didn't add any information about it, but I can share my experience. Just from your comment, the fact that the client is reporting the 'EVENT' twice, tells me that your server is sending it twice OR you set up 2 listeners on your client. Server is sending twice case-scenario:This could happen if you're trying to build state into your connections. Meaning if they're supposed to receive the event under a certain scenario so you end up attaching multiple listeners server-side. Logging all events on your server and who called it will help you catch these. This is not dart code, but this should give you an idea of what you could do on your server. this.io.on(CLIENT_EVENTS.SESSION.CONNECTION, (socket) => {
new SessionHandler(io, socket);
new LobbyHandler(io, socket);
console.log(`User ${(socket as any).username} (${(socket as any).userId}) connected with socket id: ${socket.id}`);
// Log all events when received by the server
socket.onAny((eventName: string, ...args: any) => {
console.log(`Websocket event: ${eventName} called by ${(socket as any).username} (${(socket as any).userId}) under socket id: ${socket.id}`);
//console.log("Args given: ");
//console.log(args);
});
socket.on('disconnect', () => {
console.log(`User disconnected: ${(socket as any).username} (${(socket as any).userId}) with socket id: ${socket.id}`);
});
}); Multiple client listenersLets say you're navigating to a page, and then you want to listen for the messages sent in a group chat, so that you can print new messages. If you navigate there, and call Event handlers are a list of events handlers attached to events. It's not right to say that only 1 action should happen for every event, you might want multiple things to happen at once. Always need to keep that in mind. |
well you maybe using cubit with io socket
so here you are adding everytime all list of messages not the last one so here the state contain all the list so when you need to add try like this |
I am having the same issue because I had reinitialized the socket class which is repsonsiblr for makeing connection |
Hello. I use this package in my flutter app, I faced a problem. Sometimes when user is sending message through socket, they received duplicate messages; actually socket.on('EVENT', (data){}) is performed 2 times. after restarting app, this bug fixed.
How can I fixed it? is it a server side bug or client side? How can I get more information about this?
Thanks
The text was updated successfully, but these errors were encountered: