Socket connection is not receiving event updates in Android.
Describe the bug
Unable to receive updates from the socket server on the client. I am able to create a successful connection and emit messages too. However, I am not receiving any updates in the event callback.
Version used : adhara_socket_io: ^0.1.11
To Reproduce
Below is the code used to connect:
socket.on("connect", (response) {
print(response);
socket.emit("join", [{
"channelName": channelName }]);
`socket.on("event_name", (data) {
print(data);
});`
}); socket.connect();
I receive emitted message on the server successfully using socket.emit.
Expected behavior Data received in the socket.on callback.
did you use socket.emit('event_name', data); on the server side?
No, I have used it on the client end.
Sent from my iPhone
On 13-Jun-2019, at 6:59 PM, Ken <[email protected]mailto:[email protected]> wrote:
did you use socket.emit('event_name', data); on the server side?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/infitio/flutter_socket_io/issues/30?email_source=notifications&email_token=AD2APVQUNN755GD6YTDZHZ3P2JDS5A5CNFSM4HXWOB62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXTWDHI#issuecomment-501703069, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AD2APVWNMW3EZP6SI4LBYYTP2JDS5ANCNFSM4HXWOB6Q.
the socket.on('abc'...) will be fired only when the other party uses socket.emit('abc'...) to trigger it
Hi Ken,
Yes, our servers our sending messages using socket.emit. Am I missing something here?
Regards, Saarang Tiwari
From: Ken [email protected] Sent: Thursday, June 13, 2019 7:27 PM To: infitio/flutter_socket_io Cc: Saarang Tiwari; Author Subject: Re: [infitio/flutter_socket_io] Socket connection is not receiving event updates in Android. (#30)
the socket.on('abc'...) will be fired only when the other party uses socket.emit('abc'...) to trigger it
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/infitio/flutter_socket_io/issues/30?email_source=notifications&email_token=AD2APVRGDFO4HSZTA4FAVZLP2JG5JA5CNFSM4HXWOB62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXTYZMI#issuecomment-501714097, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AD2APVUJ74QMDRVYUWISF6LP2JG5JANCNFSM4HXWOB6Q.
There is no automatic callback in socket.io
What happens in our architecture is whenever the client emits an eventName with correct data then we connect them to the socket and start emitting data for them from the server end.
socket.on("eventName", _callback) is supposed to get that data, which works on socketIO which is the native library for android, iOS, and web.
In this link: https://socket.io/blog/native-socket-io-and-android/. I am referring to the socket.on() which starts receiving the data from the server.
From: Ken [email protected] Sent: Thursday, June 13, 2019 7:41 PM To: infitio/flutter_socket_io Cc: Saarang Tiwari; Author Subject: Re: [infitio/flutter_socket_io] Socket connection is not receiving event updates in Android. (#30)
There is no automatic callback in socket.io
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/infitio/flutter_socket_io/issues/30?email_source=notifications&email_token=AD2APVT2VP6WD45FWDCH2DDP2JIQLA5CNFSM4HXWOB62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXT2GAA#issuecomment-501719808, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AD2APVX6R62DGSXVMUQJ4PDP2JIQLANCNFSM4HXWOB6Q.
- on client side:
socket.on('fromservertoclient', (data) {
// do something with data
print('got response from server')
});
socket.emit('fromclienttoserver', [data]);
- on server side:
socket.on('fromclienttoserver', function(data) {
// do something with data
console.log('got message from client');
// now use emit to callback
socket.emit('fromservertoclient', data);
});
you'll see 'got response from server' on client side
This is what exactly is happening. But still not getting any response.
From: Ken [email protected] Sent: Thursday, June 13, 2019 8:00 PM To: infitio/flutter_socket_io Cc: Saarang Tiwari; Author Subject: Re: [infitio/flutter_socket_io] Socket connection is not receiving event updates in Android. (#30)
- on client side:
socket.on('fromservertoclient', (data) { // do something with data print('got response from server') }); socket.emit('fromclienttoserver', [data]);
- on server side:
socket.on('fromclienttoserver', function(data) { // do something with data console.log('got message from client');
// now use emit to callback socket.emit('fromservertoclient', data);
});
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/infitio/flutter_socket_io/issues/30?email_source=notifications&email_token=AD2APVUOUODKKKT3ZNQS3NLP2JKW5A5CNFSM4HXWOB62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXT4F6Q#issuecomment-501727994, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AD2APVVJ6Z23LDFO3IW64JTP2JKW5ANCNFSM4HXWOB6Q.
@saarang1995
In my previous comment, we have the following FACTS:
-
The client is able to connect the server.
-
The server is able to receive a message from the client and print ('Got message from CLIENT');
-
The server, right after receiving the message from the client, sent a response to the client.
-
The client, got the response from the server and print ('Got Response from SERVER').
A COMPLETE client -> server, server -> client communications are established, and both can receive message from the other party, what ELSE do you want exactly?
In you previous comment "But still not getting any response", do you mean:
(a) "The client is still not getting any response from the server?" or (b) "The server is still not getting any response from the client?"
@lhcdims
I am answering point by point:
- The client is able to connect the server. -> YES
- The server is able to receive a message from the client and print ('Got message from CLIENT'); -> YES
- The server, right after receiving the message from the client, sent a response to the client. -> NO -> Server doesn't message right away it just connects the client successfully and the client can then listen to the events like below:
socket.on('fromservertoclient', (data) { // do something with data print('got response from server') }); - The client, got the response from the server and print ('Got Response from SERVER'). -> NO
(a) "The client is still not getting any response from the server?" or (b) "The server is still not getting any response from the client?" -> (b) is working but (a) is not.
@saarang1995,
Hi there, this is rare, because I don't have the problem you mentioned!(I got 4 Yeses for points 1 to 4!) I tried to remember the times when my socket.io connections were not successful, the only thing I can remember is I was using Android 9 (Android Pie) mobile phone to connect to the socket.io server, and forgot to set "allow clear text " in androidmanifest. (Android Pie, by default, allows HTTPS ONLY)
<application
tools:replace="android:label"
android:name="io.flutter.app.FlutterApplication"
android:label="YourAppName"
android:usesCleartextTraffic="true"
android:icon="@mipmap/ic_launcher">
If any of your user uses Android 9, pls. check if android:usesCleartextTraffic="true" is inside the application tag of your androidmanifest.xml.
This may solve your problem, I'm not sure.
I'm having the same problem,server is emitting message but the event on client side is not picking up the message
@saarang1995 Were you able to solve this problem? Seems like i'm facing the same issue.
same problem @saarang1995
@TaavishThaman and @vishweshsoni I am working on a solution and if I could resolve it then will definitely let you know.
@saarang1995 @TaavishThaman Hi i have implemented websocket completely using https://pub.dev/packages/flutter_socket_io#-readme-tab- also i have referred this https://www.youtube.com/watch?v=FvArk8-qgCk for better understanding socket
@saarang1995 Did you succeed with this while receiving events?
Same here. I see event trigger logs but there are no callbacks.
I have come up with a solution using javascript. Please read my blog for the complete solution: https://saarangtiwari.com/blog/how-i-used-javascript-to-bridge-and-connect-to-websockets-in-flutter
Hai I have also faced the same problem, Issue is callback function(type SocketEventListener) only supports single arguments.
https://github.com/infitio/flutter_socket_io/blob/master/lib/socket.dart line:5
typedef void SocketEventListener(dynamic data);
My Fix: Changed the server-side to emit with a single argument.
Have the same problem. If the problem is what @Gowtham03 is saying then it should be highly prioritized.
Have the same problem. If the problem is what @Gowtham03 is saying then it should be highly prioritized.
Have you got any solution yet?