Using Socket to connect to Server in Pc from mobile - android

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.

Related

WAMP server: change wireless SSID and server not reachable

This is a really strange thing.
I got a working WAMP server on my laptop, installed Laravel and a web application available to my clients on the local wireless network. Everything is working flawlessy. I can communicate between my android app via the wireless AP TP-Link to the WAMP server. No need of internet, this is a LAN just for devices behind.
Now, I decide to change the SSID of the AP. Change from "Zapp" to "Polls".
Restart everything: AP, laptop, mobile phone. The server is not more reachable by my mobile phone.
I can ping the IP address using a terminal app, but I can't access to it anymore. This, just changing the SSID. If I revert to "Zapp" SSID, everything work again.
I checked IP's: the change of SSID not change IP's of clients.
Could anyone explain and help?
Technical devices:
AP: TP-LINK TL-WR841R
Server WAMP v. 3.0.6 on a Toshiba Laptop
Android Phone OS 7.1 OnePlus3
Check Windows firewall profile. It might classify the network with the other SSID as Public and ports are not opened?

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.

Can't connect to laptop webserver after tethering to android phone

Searched several threads and I'm still having issues. I've tethered my laptop to my mobile phone and I'm using the data on it. I checked the IP address assigned to my laptop and made sure I'm using it, set up the apache webserver to listen on a port (no IP specified). And I can't connect from my mobile phone to my laptop web server.
Using localhost in laptop web browser works but it won't work if I use the IP specified by the android device after I tether. Also can't connect to laptop webserver from phone's mobile browser either.
Why can't I connect to my local webserver on my laptop from my mobile phone?
I've tethered both with USB and mobile hotspot and successfully shared the internet connection, but using ipconfig from the command prompt in windows I never can connect using that IP http://:3128/ 3128 is the port I have apache listening on (because I had IIS before too). Never works.

Android Client App with 3G and WIFI Network

I'm developing an application that need an internet permission all the time.
When there is a WIFI connection the application can connect to my server (if they're in the same network)
actually I have 2 question..
1) Lets say that the server is connected to network A and the client is connected to Network B (on
WIFI) why it doesn't show me on the server side the message that I send?
I made a simple project that when the client is connecting to the server it send "hello" to the
server, the server read it and tell me the address of the client and the message (print to the
console), it works fine when both server and client are at the same Network.. but when they're in
different networks it doesn't work.
2) How a 3G application is working? how can I connect the client who uses a 3G network to my server?
When you are on the same network then you give the the ip the ROUTER gave to your pc and phone (assuming that what your using) and it looks something like 192.168.0.101\2 (its your router Default address + 1 each time a device connects to the router) ...
The problem is that when you want to connnect from an outside source you must give the ip of your real address given by your ISP.
go to command\terminal and type ipconfig and look for IPv4 ------ thats your real ip when looking from the "outside" world , now thats not all you also need to configure your router to port forwad the ports your using to the specific PC that is the server.
How what and why : Port Forwarding
hope this helps.

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

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

Categories

Resources