Mobile device can't connect to web server in my computer - android

I'm developing an android application that connects to a web server to get info. I'm using HTTP Client library to connect with the web server.
I've two scenarios:
Emulator and the web server both of them installed in the same PC. The application works perfect.
Android mobile (Xperia P) connected with my PC via USB cable, and the web server installed in my PC.
In the second scenario, the application can't connect with the web server.
If I have 3G disabled, an "network unreachable" error message is received.
If I have 3G enabled, an "java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)" error message is received.
So, I would like to test my application in a real device, and the application needs to connect with the web server that is installed in my PC.
How could I do visible the web server to the android devive? I would like to have the mobile devive in the network of my PC.
Thanks

Try the following. Make sure that the phone's wifi is turned on and the phone is connected to the same network as your development machine.
Now, instead of "localhost" or "127.0.0.1" use the I.P Address of machine (assigned by DHCP for example) while calling the webservice.
Hope this helps.
Best Regards,
Anay

Related

How can I connect an android client to my XMPP (ejabberd) server, hosted on my local machine (Windows based OS)?

I want to test my ejabberd (xmpp) server, which I've hosted on my laptop, which is working on windows 10 based OS. I want to connect my android client to this server. So I went on to the internet, and found some solutions. But they seem don't work for me. This is what I've tried:
1.) Create a hotspot on a phone. Don't use data/wifi connection, as server is already on the machine.
2.) Connect the laptop to the hotspot.
3.) On cmd (running as admin), type 'ipconfig', after starting xmpp server (Obviously).
4.) Copy IPv4 address (External IP), and access web panel on the mobile browser through it.
So, I hurried toward my phone, and typed
http://[IPv4 Address]:[port open on the server for incoming connection/5280]/admin
But it(browser) throws 'Can't reach the webpage' error.
When I run
http://localhost:5280/admin
on my laptop, I could easily access my web portal, but It's unreachable on my android phone. What can I do now?
Well I solved this problem by accessing IPv4 of my laptop through my wifi router, and connecting to the port of my server through it. Initially, my browser (both of my laptop and my phone) weren't able to reach the server's port. But I later figured out it was problem in my .yml configuration file. Server wasn't set to listen all the IPv4 calls, instead it was listening to all IPv6. So I changed this, and it then become accessible to all devices on the same wifi. So it was my bad idea to connect it through the hotspot :P

How to make visible my web server by android mobile

I have a web server running on a mac laptop. This laptop is connected to the network by my android smartphone (which receives the network by mobile operator). I would like to make visible my web server from outside, so I installed a port fowarding application on my smarthone and associated its port 8080 to the port of my laptop 80.
Then I found the IP address of my mobile device by the site http://whatismyipaddress.com/ and I tried to connect by using as URL mobile.ip:8080. The connaction failed. So could anybody tell me where I am wrong?
Thanks in advance for your help

How to connect to a local server using windows hosted network

I am programming an Android app which connects to a TCP server running on my computer using sockets. This works perfectly fine as long as both my computer and my smartphone are connected to the Wi-Fi of my router.
I want it to also work when my computer and my phone are not connected to the Wi-Fi. Therefore I configured a Wi-Fi hotspot using hosted network on my computer. My smartphone recognizes the Wi-Fi and is able to connect to it. But now my app can't connect to the server running on my PC although I changed the code to the new IP that I got by using ipconfig on my PC.
I downloaded an app named "Fing" from the Google play store. The app shows all devices in a network. It does show my computer under the right IP address. I don't understand why my app can't connect to the server running on the PC.
On the one hand, I don't think that the problem is in the app's code, because it works on the router's Wi-Fi network. On the other hand, I doesn't seem to be a setup mistake either, because Fing is detecting my PC.
Do you have any ideas what the problem might be, or any other solution for my needs?
I actually wrote the TCP server myself using c#. I configured the Server to listen to all of my computers networkinterfaces usingIPAdress.IPv6Any. I also did configure it as dual mode socket so it can accept ipv4 and ipv6 connections. I will post the code when i am back home. So the TCP server also looks ok to me.

Using Socket to connect to Server in Pc from mobile

I wrote an app to connect to java server running in PC. It works fine in emulator but its not working when i try the same from my mobile. I used the Mobiles 3G network to connect to IP address.
(Based on question comment)
I assume that your server application is running on the same machine as the android emulator. In this case the emulator can reach your server with 10.0.2.2.
If you're trying to contact your server via mobile 3G you have to use the IP of your Internet connection (What is my IP?). The request will reach your router. The router has to forward this request to your server machine. So if your server has a local IP 192.168.0.10 and it listens to port 2412 your router should forward all incoming request for this TCP port to this IP.
You should allow the 3G internet in Settings. (Emulator doesn't need this, it uses ethernet connection of your PC).
Your application should diagnose the state and possibilities of Internet connection and report it to you as a user of the debug mode. Or/and something - to the usual user.

android: connect to servlet

I have to connect to server(servlet on tomcat) always running and process the http request and send the response..
Client is Androbile mobile application.
I aware that I can connect using HTTP Client..
But to connect from device to server running on my PC...
I want to check if I can connect to my localhost from device...
Also if I want to use mobile network to connect from any android device on which this app is deployed.... Do I have to host this website(Server)...
Please help me
You can do it if you have WiFi, simply join network and then in browser provide IP of your pc. As for wider accessibility, then yes you need to get host

Categories

Resources