Android Question How to connect to my PC localhost instead of mobile localhost

Javier Campo Martinez

Member
Licensed User
Greetings !!!
I'm trying to connect to a MySQL database which resides in my PC.
I installed Wampserver, but i use the port #82 instead of #80 (i'm using port #80 for IIS )
When I invoke this method,
B4X:
Dim job As HttpJob
job.Initialize(JobName, Me)
job.PostString("http://localhost:82/ws/webservice.php", p_Parametros)

I obtain this error message

B4X:
java.net.ConnectException: Failed to connect to localhost/127.0.0.1:82
I read an article that says this "localhost" is not the PC localhost, but the mobile localhost.

Is there any way to access my PC localhost ?

Thanks in advance, and sorry for my bad english !!!!
 

Javier Campo Martinez

Member
Licensed User
You haven't wrote it, but I guess that you are using the emulator, right?

Use this ip address to access the PC local host: 10.0.2.2

Hi Erel !!!
Thanks for your kind answer !!!

First of all, I'm testing my code via USB Debugging, that is, connecting my mobile to the PC via USB cable.

I changed "localhost" to "10.0.2.2." ( keeping port "82") and now i obtain this error message:

B4X:
ResponseError. Reason: java.net.SocketTimeoutException: failed to connect to /10.0.2.2 (port 82) after 30000ms, Response: 
java.net.SocketTimeoutException: failed to connect to /10.0.2.2 (port 82) after 30000ms

Looking forward for comments on above.

Best regards!!!
 
Upvote 1

asales

Expert
Licensed User
Longtime User
You need the IP of the PC and use it like this:
B4X:
http://192.168.0.100:82/ws/webservice.php
where 192.168.0.100 is the IP of the PC.
 
Upvote 0

Javier Campo Martinez

Member
Licensed User
You need the IP of the PC and use it like this:
B4X:
http://192.168.0.100:82/ws/webservice.php
where 192.168.0.100 is the IP of the PC.

Hi Asales.
First of all, thanks for your kind reply.
The IP address you gave to me, it's not working either. However, I'm still investigating.

Thanks in advance.
 
Upvote 0

Javier Campo Martinez

Member
Licensed User
Solved.

I just used DOS command "ipconfig", and it displayed the IPv4 IP address.

I changed the IP address in the URL to point to this IPv4 IP address, and the connection with my PC localhost is working.

Obviously, in production it will be another one ( "the official" ... so to speak) so it will be customizable.

Thanks for your kind comments, and I hope this solution works for everyone !!!
 
Upvote 0
Top