flutter_socket_io icon indicating copy to clipboard operation
flutter_socket_io copied to clipboard

Socket connection is not receiving event updates in Android.

Open saarangtiwari opened this issue 6 years ago • 22 comments

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.

saarangtiwari avatar Jun 13 '19 06:06 saarangtiwari

did you use socket.emit('event_name', data); on the server side?

lhcdims avatar Jun 13 '19 13:06 lhcdims

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.

saarangtiwari avatar Jun 13 '19 13:06 saarangtiwari

the socket.on('abc'...) will be fired only when the other party uses socket.emit('abc'...) to trigger it

lhcdims avatar Jun 13 '19 13:06 lhcdims

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.

saarangtiwari avatar Jun 13 '19 14:06 saarangtiwari

There is no automatic callback in socket.io

lhcdims avatar Jun 13 '19 14:06 lhcdims

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.

saarangtiwari avatar Jun 13 '19 14:06 saarangtiwari

  1. on client side:
socket.on('fromservertoclient', (data) {
  // do something with data
  print('got response from server')
});
socket.emit('fromclienttoserver', [data]);
  1. 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

lhcdims avatar Jun 13 '19 14:06 lhcdims

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)

  1. on client side:

socket.on('fromservertoclient', (data) { // do something with data print('got response from server') }); socket.emit('fromclienttoserver', [data]);

  1. 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.

saarangtiwari avatar Jun 15 '19 04:06 saarangtiwari

@saarang1995

In my previous comment, we have the following FACTS:

  1. The client is able to connect the server.

  2. The server is able to receive a message from the client and print ('Got message from CLIENT');

  3. The server, right after receiving the message from the client, sent a response to the client.

  4. 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 avatar Jun 15 '19 07:06 lhcdims

@lhcdims

I am answering point by point:

  1. The client is able to connect the server. -> YES
  2. The server is able to receive a message from the client and print ('Got message from CLIENT'); -> YES
  3. 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') });
  4. 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.

saarangtiwari avatar Jun 16 '19 07:06 saarangtiwari

@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.

lhcdims avatar Jun 16 '19 08:06 lhcdims

I'm having the same problem,server is emitting message but the event on client side is not picking up the message

jainsanil18 avatar Jun 20 '19 11:06 jainsanil18

@saarang1995 Were you able to solve this problem? Seems like i'm facing the same issue.

taavishthaman avatar Jun 20 '19 12:06 taavishthaman

same problem @saarang1995

vishweshsoni avatar Jul 11 '19 13:07 vishweshsoni

@TaavishThaman and @vishweshsoni I am working on a solution and if I could resolve it then will definitely let you know.

saarangtiwari avatar Jul 11 '19 14:07 saarangtiwari

@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

vishweshsoni avatar Jul 11 '19 23:07 vishweshsoni

@saarang1995 Did you succeed with this while receiving events?

MobilyteApps avatar Nov 12 '19 20:11 MobilyteApps

Same here. I see event trigger logs but there are no callbacks.

ataberkw avatar Nov 15 '19 15:11 ataberkw

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

saarangtiwari avatar Jan 07 '20 06:01 saarangtiwari

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.

Gowtham03 avatar Feb 29 '20 13:02 Gowtham03

Have the same problem. If the problem is what @Gowtham03 is saying then it should be highly prioritized.

arisAlexis avatar Mar 22 '23 10:03 arisAlexis

Have the same problem. If the problem is what @Gowtham03 is saying then it should be highly prioritized.

Have you got any solution yet?

jatin-web avatar Sep 26 '23 12:09 jatin-web