Skip to content
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

Team, please respond: Connection timeout on Android #151

Open
idevchandra opened this issue Jan 28, 2021 · 9 comments
Open

Team, please respond: Connection timeout on Android #151

idevchandra opened this issue Jan 28, 2021 · 9 comments
Assignees

Comments

@idevchandra
Copy link

Describe the bug
Android connection is timingout. But, iOS is fine.

Environment:

Server: Node.js
Client: Flutter with Adhara socket.io
iOS Emulators: iOS 14.2 iPhone 12 Pro and iPhone 12 mini
Android Emulators tried: Pixel 3a API 30. Pixel 4 API 30.

Have you tried reproducing the issue with example available in this repo?
Yes

To Reproduce
Steps to reproduce the behavior:

  1. Have the below simple node.js server
// server.js
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io')(server);

io.sockets.on("connection", function (socket) {
    console.log("Connected " + socket.id);

  socket.on('disconnect', function () {
    console.log('client disconnect...', socket.id)
  })
});

listen_port = process.env.PORT || 7000;
server.listen(listen_port);
  1. On Terminal, run node server.js

  2. On Terminal run adb -s emulator-5554 reverse tcp:7000 tcp:7000
    The behavior of the app is same with or without running the above command.

  3. Change this repo example, as shown below, with the actual server URL - localhost.
    Because, it is Android emulator, I used 10.0.2.2. I also tried with localhost, 127.0. 0.1 too. With all the three, it is same behavior - "Connection Timeout"

    String URI = Platform.isIOS ? 'http://localhost' : 'http://10.0.2.2';
    ...
    ...
    SocketIO socket = await manager.createInstance(SocketOptions(
        URI,
        nameSpace: (identifier == "namespaced") ? "/adhara" : "/",
        query: {
          "timestamp": DateTime.now().toString()
        },
        enableLogging: true,  // I am sure this has nothing to do with connection. I tried `true` too!
        transports: [
          Transports.WEB_SOCKET 
        ] 
        ));
  1. Run the app on iOS and Android simulators.

Expected behavior
iOS Simulator and Android Emulators should be able to connect to server.

Device details:

  • Device Type: Android Emulator
  • Model: Pixel 4
  • OS: Android API 30
  • Package Version adhara_socket_io: ^0.4.1

Relevant Logs

I/flutter ( 7913): Connecting to socket...
W/a4m.flutter_ap( 7913): Accessing hidden method Ldalvik/system/CloseGuard;->get()Ldalvik/system/CloseGuard; (greylist,core-platform-api, reflection, allowed)
W/a4m.flutter_ap( 7913): Accessing hidden method Ldalvik/system/CloseGuard;->open(Ljava/lang/String;)V (greylist,core-platform-api, reflection, allowed)
W/a4m.flutter_ap( 7913): Accessing hidden method Ldalvik/system/CloseGuard;->warnIfOpen()V (greylist,core-platform-api, reflection, allowed)
I/flutter ( 7913): Log: onConnectError. Reason -> io.socket.client.SocketIOException: timeout
I/flutter ( 7913): Log: onConnectTimeout: Reason -> 20000
I/flutter ( 7913): Log: onConnectError. Reason -> io.socket.client.SocketIOException: timeout
I/flutter ( 7913): Log: onConnectTimeout: Reason -> 20000
@vikas-shrma
Copy link

@idevchandra did your connection timeout randomly or after particular time interval?

@vikas-shrma
Copy link

try using this dependencies

 adhara_socket_io:
    git:
      url: https://github.com/aslamanver/flutter_socket_io

@Danish777
Copy link

yes, I am facing same issue

@SmartNodeAutomation
Copy link

Yes, I am facing same issue. cannot connect socket with Android phone.

@tiholic
Copy link
Contributor

tiholic commented Apr 6, 2021

@idevchandra @vksBhardwaj @Danish777 @SmartNodeAutomation

It could possibly be due to usage higher socket.io version on server side.

Currently this package supports only v2 socket.io

Please track v3/v4 support here: #160

@tanmoydas61999
Copy link

Socket connection works fine when connected to localhost(Ex - http://172.20.10.3:4000/),
but when connected to url which is hosted on heroku,it stops working.
Please help.

@vikas-shrma
Copy link

vikas-shrma commented Jun 18, 2021 via email

@tanmoydas61999
Copy link

Which headers?
Help is very much appreciated

@tiholic
Copy link
Contributor

tiholic commented Jun 25, 2021

@tanmoydas61999 we do add additional configuration when hosting socket server in AWS to allow upgrade to socket from http: #21 (comment)

May be something similar has to be done with heroku too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants