I'm using Flutter with:
socket_io_client: ^3.1.4Socket.IO server:
4.8.1
The Socket.IO connection itself is successful. I can see the connect event and the socket is connected.
However, when the app is installed fresh from Google Play Store, the socket appears to connect but does not receive/handle my application events.
The same code works correctly in debug/local builds.
My Socket.IO configuration is:
socket = io.io(
url,
io.OptionBuilder()
.setTransports(['websocket', 'polling'])
.disableAutoConnect()
.enableReconnection()
.setReconnectionAttempts(10)
.setReconnectionDelay(1000)
.setReconnectionDelayMax(5000)
.setTimeout(20000)
.enableForceNewConnection()
.setExtraHeaders({
"Authorization": token,
})
.build(),
);
The socket connects successfully:
socket.onConnect((_) {
print('SOCKET CONNECTED');
});
But events such as:
socket.on('ride_request', (data) {
print('RIDE REQUEST: $data');
});
are not being received/handled on a fresh Play Store installation.
Important details
This is not a connection failure.
The sequence is:
Fresh Play Store installation
↓
Socket connects
↓
Server is running
↓
Server emits events
↓
Flutter client does not appear to receive/handle those events
Debug/local installation:
Socket connects
↓
Events are received correctly
What could cause this?
Could this be caused by:
Event listeners being registered after the server emits the event?
Listeners being removed somewhere by
clearListeners(),disconnect(),destroy(), ordispose()?Multiple Socket.IO instances being created?
enableForceNewConnection()creating a different socket instance?The release build tree-shaking/obfuscation affecting Socket.IO event handling?
Event names being different between the production server and client?
The authentication middleware allowing the connection but assigning the wrong user/session, causing events to be emitted to a different socket?
Socket.IO rooms not being joined correctly in the release build?
Events being emitted before the client joins the appropriate room?
Some difference in initialization order between a fresh installation and subsequent launches?
What is the best way to debug this when the socket connects successfully but application events are not being received?
I can also provide the server-side io.emit(), socket.emit(), room/join logic, and Flutter listener registration code if needed.