1

I'm working on a project in which I need to communicate between an Android device and a computer. To initiate a connection between these two device I thought using a Rest API mechanism with the following architecture :

My current flutter snippet looks like :

Jaguar server = Jaguar(port: 8080);
server.get("/", (context) => 'Hello');
await server.serve();

When accessing to "localhost:8080" from a web browser directly on my Android device, I get the "Hello" message but when trying to do the same thing from my computer (which is on the same network), I get a timeout error (on "192.168.0.10:8080").

It seems that my flutter (or my device) does not expose the web server to the rest of my network but I don't know why.. Do you have an idea ?

7
  • How do you try to access exactly the server from your computer's browser? Commented Dec 24, 2021 at 10:02
  • By trying to reach "192.168.0.10:8080" Commented Dec 24, 2021 at 10:20
  • Is your Jaguar server bound to localhost/127.0.0.1 ? Commented Dec 24, 2021 at 10:31
  • Check firewall settings in your Android device, port 8080 should be open to serve incoming requests with TCP protocol. Commented Dec 24, 2021 at 10:31
  • @blackapps My server bound on 0.0.0.0 (default value) Commented Dec 24, 2021 at 10:37

2 Answers 2

2

After a while, I found the solution. It's because since the API 28, Android blocks clear text traffic.

To solve this issue, we must override android:usesCleartextTraffic="true" like

<application
        ...
        android:usesCleartextTraffic="true">
...
</application>
Sign up to request clarification or add additional context in comments.

Comments

1

My solution was to bind the server to 0.0.0.0 instead of localhost.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.