N
N
Nikita2019-01-27 16:10:15
Java
Nikita, 2019-01-27 16:10:15

Why is the socket not connecting on a real device?

running on emulator

Socket socket = new Socket("10.0.2.2", portNumber);
and everything works fine
. But on a real device, what I have not tried does not work, neither 127.0.0.1 nor 10.0.2.2
Error:
java.net.ConnectException: failed to connect to /127.0.0.1 (port 5000) from /:: (port 33717): connect failed: ECONNREFUSED (Connection refused)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikita, 2019-01-27
@NeToster

Solved the problem by getting an IP using hostname -I (for linux)

K
Konstantin Malyarov, 2019-01-27
@Konstantin18ko

127.0.0.1 is a request to itself (the phone calls itself)
10.0.2.2 is a request to the local network.
Show what the request for 10.0.2.2 says

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question