Time out during the connection to local server from physical device - android

I downloaded Apache 2.2 from here I know that this is old version but anyway I need it. Then I launched Android emulator and tried to access to server and it worked. I used 10.0.2.2 IP address with 8080 port.
Next, when I try to connect to server using PC on which I launched the server, it works if I provide IPv4 address of PC for example 192.154.1.23:8080.
Well, when I try to connect to server using my physical device (my mobile phone) I can't do that even if I try IPv4 address of my PC with 8080 port. It just tells me about time out.
What should I do to connect to server from my phone?
P.s. I use same WI-FI network on both devices

Solved it.
Well first of all you need to set type of your connection to private and make sure that this is trusted network, for example your home network or your own WI-FI. But you also can do it with public network but this is too risky!!!
Then go to Firewall settings and allow Apache application to communicate with other devices. Choose it in the table of allowed app and features and check the box for private network, then press OK. I recommend to restart Apache server.
That's it! Now you can connect to server using IP address of your PC, on which you installed Apache server, from any device like other PC or mobile phone but you have to be in same local network. If you want to access your server globally you need to ask your ISP (Internet Service Provider) to get static IP address to make it visible in global network.

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

android volley library does not work on local IP

volley is not working when i want to fetch data from a system on my local network.
where URL is like http://192.168.x.x/data.php
it works well on emulator but not on a real device. it show a time our error.
even i tried setting a maximum time our and retry policy. but in vain.
There are two ways to solve this:
a) keep your device connected to the PC which is connected to your local network either using lan or wifi. Keep debugging mode on. Use ipconfig to check your pcs ipv4 address and use that.
forward your server's port on your router and then use the ipv4 address found on your pc's ipconfig command.
c) Best option-> i use this. Forward your pc's server port on your router, Go to your router's DHCP configurations and give your pc mac a preferred DHCP ip to make sure your router always gives that local ip to your pc(global will still be dynamic if you dont have a static ip). Register to a DDNS and use the set ip above and you will be able to access your web service from anywhere in the world. (i use dynudns for the ddns part)
see How can I access my localhost from my Android device? for other ideas
In the first two steps, make sure that the mobile is connected via wifi so that the router can forward it requests. in third, it can be connected to the internet anyway it likes. Also in the first, you will have to change the url everytime your local ip changes.
In second option, the dns will give a tool for auto ip updation :)

ActionScript 3.0 How to properly connect? "localhost" or "192.168.XXX.XXX"?

I am struggling with this for three days now. It is an android client application that connects to the server AIR application through Wifi on local network.
I need my application to connect to the server every time it is launched without asking the user to enter local IP, in case it changed.
It seems there are many ways to make sure the connection is successful, but I want to make sure I can go without the help of RTMFP or PHP or SharedObject stuff.
I am able to get local IP using NetworkInterface and NetworkInfo ANE from Android client. Then I use the variable to
mySocket.connect(ipAddress, 8888);
But there is a problem:
1) When debugging on Android via Wifi
The detected IP 192.168.137.2
2) When debugging on Flash, on computer
The detected IP 192.168.137.3
So, the local IPs are not the same. So client fails to connect. Everything works perfect, if I manually set that IP, but I need a code that works, even if the IP on local network changed.
As I mentioned making a textInput field in case IP changed and ask the user manually enter IP is not an option.
My question is why using "localhost" as host parameter of socket.connect(host, port) does not work? If it did, there would be no need for detecting local IP at all. "localhost" works for me only if the client is running on computer, but not Android.
Is it the problem with Security Policy file? if so, I have no idea how to use that. I can't find any tutorial on that.
You have two devices
1. Android device running an app and acting as a client
2. Computer running an AIR app and acting as a server
Each of those devices will have it's own IP address on the network. In your case android device IP is 192.168.137.2, and computer IP is 192.168.137.3.
In order for client to connect to server there must to be some means of delivering server IP to the client. Normally for an app like this you enter server IP address manually in settings, or have one central place available on the net where server registers it's IP address and client fetches the address from there.
Since you don't want to use any of these options the last resort would be implementing local area network scanning. Where you scan all the segment 192.168.137.* and search for opened port reserved for server. That of course is not good implementation but could work if project is for your own use.
Lastly "localhost" is name mapped to loopback IP 127.0.0.1 which is special address and is used to connect to the same device app is running on. In your case if android app is connecting to localhost it is trying to connect to the android device itself.

How to run a Apache Tomcat Webserver on my PC and access if from a real Android Device?

I have a Tomcat 7.0 server running on my PC, I access the servlet via Emulator through Url
http://10.0.2.2:8084/MyServer
I am struggling with this for few hours now. I have understood the following steps to achieve this
I need to have a Static IP address? So I am using No-IP Free to covert dynamic IP (I have a dial-up connection) to Static IP.
I need to change the firewall rules in Windows 7. I tried changing Inbound Rules for 'port 8084', but it did not work.
My Question is how to access the same server on my PC via a real Android device having GPRS connection?
Thanks so much.
wifi is the best answer. Get your machine and phone on the same network. If that isn't an option, I'd suggest local tunnel: http://progrium.com/localtunnel/
As long as your server has a public IP address, you'll be fine. The first you should try is to access it from your device using the known IP address and then go for the name resolution, for which DynDNS or No-IP Free will be valid options.
Let's say your pablic IP at any given time is 1.2.3.4, just try
http://1.2.3.4:8084/MyServer
and it should work. Then configure any of the mentioned services and try using the host and domain name.
Firewall rules on your Windows PC and wired/wireless router will both need to allow incoming connections to port 8084.
On the router, set up incoming connections to 8084 to redirect to your Windows PC's local IP address (127.0.0.1). This is called "port forwarding" – look into your router's manual on how to do it.
Once your router forwards incoming port 8084 requests to your Windows machine, you can access it from the outside:
http://your-dynamic-address.com:8084/MyServer

Send a POST request from an Android phone to Visual Studio in localhost

I need to send a POST request to my Visual Studio localhost web server using my Android application. I need to do this for debug purposes.
I don't know how to allow my phone to reach the localhost. I tried to use the computer IP address but it doesn't work. Any help?
You probably need to modify your firewall on your computer to allow incoming connections on the necessary port.
In the end, I used a phone emulator to access locally the localhost server and it worked really well. From the phone, I called the address 10.0.2.2 and it connected to the localhost server.
Your question is mis-stated.
Assuming what you want to do is access a server running on your PC:
You will have the most luck putting the phone and the PC on the same local area (wifi) network.
You may be able to achieve a local network over USB with some tethering solutions.
If the PC and the phone are not on a the same local network, the PC will need to have a globally routable IP address, in order for the phone on it's mobile network to be able to reach it. Many personal ISP solutions do not easily allow for this, due to dynamic IPs, personal routers implementing NAT, or with the IPv4 space being exhausted carrier grade NAT meaning subscribers do not have a unique IPv4 address even temporarily.

Categories

Resources