Comments (3)
Faced a few of these, never had one that wasn't my fault.
How can I get more information about this?
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 listeners
Lets 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 _socket.on('message-sent', _someEventHandler);
but DON'T call _socket.off('message-sent', _someEventHandler);
, you will end up attaching 2 event listeners. It's also important to note that calling off, will only remove the event once. If you look at the code for it, it's called "remove" and not "removeAll".
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.
from socket.io-client-dart.
well you maybe using cubit with io socket
so you are displaying chat list but before it maybe like this
enter code here Expanded(
child: BlocBuilder<MessageCubit, List<Message>>(
builder: (context, state) {
if (state.isNotEmpty) {
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
messages.add(state.last);
from socket.io-client-dart.
I am having the same issue because I had reinitialized the socket class which is repsonsiblr for makeing connection
the solution was making this class so the connection will be only once
from socket.io-client-dart.
Related Issues (20)
- js version is too high. Many popular libraries depend on 0.6.x. Version is incompatible. HOT 4
- Can this package migrate `js` to `web`? HOT 2
- hot restart error
- Hot Reload Causes Multiple SocketIO Client Instances In Flutter Web
- what does the `autoConnect` property do? please review my flutter code. HOT 2
- WebSocketException: Connection to 'APIURL:0/socket.io/?EIO=4&transport=websocket#' was not upgraded to websocket HOT 4
- Usage proxy
- could we ack when we receive a new event HOT 3
- error with timeout and emitWithAck HOT 1
- This says 'client', what if i want my server in dart? anything i should be looking into? HOT 5
- Unable to get Callback of NodeJS into Flutter
- Supporting multiple versions of Socket.IO HOT 1
- [Flutter Web] IO server disconnect HOT 2
- type 'String' is not a subtype of type 'int' of 'index' HOT 2
- Flutter release build not working as expected on real device HOT 1
- WebTransport Support HOT 2
- [Flutter WASM] No transports available HOT 1
- Bug: type 'Null' is not a subtype of type 'bool'
- Incorrect argument matching in notifyOutgoingListeners
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from socket.io-client-dart.