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

Issue: Timeout Error on Emulator but Working on Flutter Web (Chrome) #402

Open
Utsav-patell opened this issue Dec 16, 2024 · 0 comments
Open

Comments

@Utsav-patell
Copy link

Utsav-patell commented Dec 16, 2024

``I am encountering an issue where my Flutter app connects successfully when run on Chrome (web), but when I run the same code on an Android emulator or a physical device, I receive a timeout error. The connection to the backend works fine in the browser, but fails on the emulator, suggesting that there may be a network configuration or connectivity issue specific to the Android environment. I have verified that the API endpoints are correctly set, and the problem appears to be isolated to the Android runtime.

Screenshot 2024-12-16 223724

class SocketService {
  IO.Socket? socket;

  void initSocket() {
    try {
      socket = IO.io(
        ApiConstants.tokenBaseUrl, // Replace with your host URL
        IO.OptionBuilder()
            .setAuth({
              'token':
                  'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NzYwNTRjMzQ3MDlhNzdiODVjNmQyOGUiLCJyb2xlIjoiU3R1ZGVudCIsIm5pY2tuYW1lIjoiVXRzYXYiLCJpYXQiOjE3MzQzNjY0MzIsImV4cCI6MTczNDk3MTIzMn0.RcTeuWGEb4JU6yqYvZrdvvwVuxu4L8IX1DHOdEOFYfM'
            })
            .setTimeout(6000)
            .setTransports(['websocket'])
            .disableAutoConnect()
            .build(),
      );

      socket!.connect().onConnect((data) {
        log(socket!.connected.toString());
        log("Connected");
      });
      socket!.on('connection', (_) {
        log("Entered");
        log('[socket] connected to server');
      });

      socket!.on('connect_error', (err) {
        log('[socket] connection error: $err');
      });

      socket!.on('connect_timeout', (timeout) {
        log("Timeout :" + timeout.toString());
      });
    } catch (e) {
      log(e.toString());
    }
  }

  void closeConnection() {
    socket?.disconnect();
    log('[socket1] disconnected');
  }
}

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

1 participant