I want to let the users browse and download their content on an android device through an internet connection.
I have successfully made a tiny HTTP server that works fine when you are on the local WIFI.
But the server cannot be reached from an outside network or when the phone is on 3G since the operator does not allow incoming connections.
The solution as I see is to let the phone make a outgoing connection to a proxy server and let the users connect to their phone through this proxy connection.
Is there an easy way to make this setup? Like a configuration in apache? I think I am looking for a reverse proxy where the server makes the initial connection to the proxy but I am not sure what the correct term is. Any hints or links to some documentation would be appreciated.
Related
I'm trying to send a chunk of data (about 1mb) from an android device to another via internet. Lets say I can get each device's IP address and open a specific socket before making the connection.
I have successfully making this connection via Wi-Fi Direct, however the distance between each device became an issue. Therefore, i need to use internet connection. I hear that WebRTC could make such connection, but it needs me to use STUN/TURN server to get other party IP addresses (which I can get without server).
I expected to have this connection pure peer to peer like Wi-Fi direct (without any use of cloud server). If a server is needed i could make one of the device act like the server.
If anyone could provide me some example of code of how to do this in kotlin, that would be much appreciated.
Thanks!
Try out WebRTCs apprtc demo. There are instructions on how to get and compile the code here https://webrtc.org/native-code/android/
You should be able to see how a data channel is established and how to send/receive that data.
I have an app that runs in an emulator. The app sends multiple messages to my local server, for manipulating data. While i was using the app in my emulator i was using:
http://10.0.2.2/path
to reach the server. I would like to use a physical device to connect to the server. Does somebody know how to do this. What adress i should use?
Assuming that your devices are on the same Network (connected to the same router) as your computer, you can expose your computer's web server (Apache, presumably?) and then point your app directly at the local network IP address that your computer has (usually something like 192.168.1.x). I have found that the least painless way to do this is to use MAMP or WAMP or LAMP depending on your OS, but of course I have no idea what your specific situation is, so that solution may in fact make things a lot more complicated rather than less.
In any event... your computer is on the network at a specific IP address, so it's just a matter of making sure that it's willing to serve this data on whatever port you are looking for it on. If you provide more specification as to your circumstances, we can give a more detailed answer.
All of the documentation, examples and questions I've seen so far on TCP connections with Android have been between an Android device and a computer. As unreliable as wireless can be, is it possible to make a client-server TCP connection between Android devices over WiFi, and if so, how?
Edit: I guess I should elaborate more on my situation.
My Droid does not respond to ping or accept incoming TCP requests from anything unless I first make the Droid a client and my laptop the server. After this initial connection is established I can then ping from my laptop, or make the Droid a server and my laptop the client. What I can't do is make one Droid the server and another a client, I always get a "No route to host" error.
It feels like there is something blocking incoming connections unless the device initiates a connection to something else, and even then the only request the device will accept is with this device. How can I make my Droid a server that accepts all incoming TCP requests from any device on my local intranet?
You should be able to. Just do like you would do with computer/device connections, except run the client and server code on the devices.
One of the neat things about the Internet is that the Internet doesn't care whether you are establishing a connection between two PC's, a PC and a phone, or two phones. I would look at the Socket documentation, that should be enough to get you rolling.
It's certainly possible. The only problem is figuring out the IP address. I don't expect a phone have a fixed IP... However, if there is a fixed "login" server somewhere in the Web which IP is known to both phones then they can do a handshake via that server and after that continue peer-to-peer.
re; The only problem is figuring out the IP address. I don't expect a phone have a fixed IP.
Try this;
Use the web browser on the phone to log into this website: It should provide you the IP address.
http://whatismyipaddress.com/
I have an android application that talks to a server app running on grails (Groovy on Grails).
Android app basically establishes a connection with this address:
url="http://192.168.2.53:8080/tma/majBtm/androidToDesktop";
It all works fine when both the server and the android phone are connected in the same lan network.
Now the problem arises when I want the phone to talk to the server while the phone is outside the local network (I need it to use edge).
I came across VPN networks which I think might help me out. (the server has dynamic IP)
So what i did was go to dyndns.com and created a new hostname and have the app successfully run on the server. The host I created was - tmagrails.dyndns.com
How do I make my phone connect to this network? What changes am I supposed to make in order to get things working?
Also, I really want to know if this is the right approach. If not, is there any way to get things going for me?
Please advice.
First you need to set up port forwarding so that port 8080 is forwarded to your 192.168.2.53 ip address. A google search on your router model should tell you how to do this. If you want to make your app more secure you will also need to look at SSL and TLS While this won't garantee your app is secure it will stop the network traffic to your app being easily read if you were to access it from an open wifi hotspot.
I got this crazy idea that I don't know is possible or not... what I want to do is set up my phone as wifi access point, then allow people to connect to it, but handle all incoming http traffic myself.
So:
phone wifi in access point mode; open wifi network (this tidbit works - yes I know it's not officially supported but then I have no intention to distribute put this app on the open market or so, it works on my phone and that's good enough for me).
client can connect to the phone (e.g. my laptop: this also works).
when client tries to open an http connection to any random server, this has to be intercepted by my app and handled by a local web server. This is the point that I'm stuck on.
The web server part shouldn't be too hard; there are (open-source) web servers available. But getting the traffic to that web server, there is the problem.
The behaviour I'm after is a bit similar to what you get when connecting to some open hotspot, like hotel hotspots, that then redirect you to a login page. This intercepting of the connection request (I suspect I have to look at DNS requests?) is what I'm after.
I have seen an app that is doing this but they require the phone to be rooted. I'm hoping to find a way to do it without rooting the phone.
Wifi hotspots would usually use IPTables to redirect port 80/443 traffic to a local web server.
I have run squid on linux machines in the past on port 3128, then sent all port 80/443 traffic to squid. Then I used squid redirect any url that I didnt explicitly allow to a local web server.
IPTables is accessible on rooted android devices only though.
And I doubt there are many proxy servers available on android, so you would have to send HTTP traffic to a proxy server over the network connection.
Like has been said, you'll need IPTables, but you'll also need a proxy server, like Squid.
Google "transparent proxy with squid", or check here:
Linux: Setup a transparent proxy with Squid in three easy steps
you do not need to have a proxy, you just need a full LAMP stack on your device and IPtables, you can mark all packets that have not been authenticated to forward through to your local page, then using php change the rule for that IP address once the address has authenticated, you could do the same for mac addresses if you wish, you would then also need a daemon that periodically reset each exception