I'm trying to write an Android app to accept TCP connections from the Internet. Sounds simple but despite weeks of head-banging, I've found no solution and now believe it impossible. I would love to have someone tell me I'm wrong.
I was encouraged by the "ServerSocket()" API function. I was able to create a listening socket (e.g. on port 2000) and connect to it from another app within my device. Unfortunately I find it is bound to (unrouteable) local address 10.0.0.150 which, of course, cannot be seen from the Internet.
I was also able to successfully connect by pointing my device to my local WIFI router and using the router's "Port Forwarding" feature to relay incoming connections to MyPublicIp:2000 to 10.0.0.150:2000. But this is not usable in the field (over an LTE connection) where I have no router.
I've searched StackOverflow and other sites but found no good answer (but plenty of inapplicable or obtuse ones).
From my reading, I hear that most (all?) carriers do not allow incoming connections to be routed to user devices, which may explain my dilemma.
PLEASE: Someone tell me I'm wrong.
I think it is possible.
Looking information about my mobile operator (mobile provider): it can provide a static IP address and my mobile device is available for incoming sessions, but only need to pay for this service.
Related
I am writing a p2p messaging Android app, and I'm trying to solve the problem of NAT on mobile networks. I cannot currently find a way for a device to connect to another listening device on a 3G/4G network due to the carrier's NAT service.
I have heard of a few NAT punch-through methods, but a lot of those involve using some sort of centralized server as a mediator. I am trying to use a completely decentralized p2p approach to accomplish this task.
Are there any feasible ways of allowing a device on a mobile network to be publicly addressable?
Thanks!
No, it is not possible. Most of the time, subscribers with IP addresses NATed are behind NAT444 and many subscribers are anycasted ( subscribers have the same IP on their mobile phone, but nated behind a different NAT devices). And 2 anycasted suscribers cannot communicate together.
The only way left you is to open a VPN to get a real IP of Internet Public.
My suggestion would be: Do not use VPN for IPv4 ! Use VPN to get a real IPV6 to your mobile phone application, and build your p2p application over IPv6.
You are fighting with very old problem that drove IETF to build IPv6.
So, go to IPv6, and forget ipv4.
The ONLY good solution for your problem is to build your app over IPv6, and your app has to bring the ipv6 tunnel to the phone.
i don't know if it's the right community to ask (i think so, by the way) so excuse me in advance if this is off topic.
I was thinking about a project in android that involves knowing how many devices are in the surroundings.
Is there a way to "discover" it? My idea is something like this:
my device sends some sort of broadcast ping via ARP (or some Data Link protocol)
Every device answers to that ping
My device counts how many response pings are and this is how many surrounding devices are.
I'm saying ARP or some Data Link Protocol because it should be "beyond wifi connection", knowing not "how many devices are connected to my network" but "how many devices surround me"
Thank you in advance!
IPv4 ARP requests are broadcasts, but they contain the specific IPv4 address of the host for which you are requesting the layer-2 address. All hosts on the layer-2 domain will receive the ARP request, but only the host with the specific IP address will respond to the ARP request.
There are many ways in which LAN discovery tools work, but none of the methods are foolproof because the network protocols were not built with LAN discovery in mind. Also, there are ways in which to configure some LAN devices so that it is difficult to impossible for the hosts to be discovered, e.g. private VLANs, where hosts on the private VLAN cannot communicate with any other host on the same VLAN, except for the gateway.
I worked on a simple app....which works by sending simple instructions to Arduino over my WiFi router, just like - 192.168.0.177/status or 192.168.0.177/currenttemp etc,while my phone is directly connected to the router.
What I am trying to achieve now,is to be able to send same instructions to Arduino(which is connected to router) over the 3G/2G data of my android(which is not directly connected to router).
I tried to research a bit,but its all is just fuzzing up things more & more....
(I m big nooooob).
So,what should I do to get that to happen?
is it--[PUBLIC IP of router]/status. I just cant understand.
Some port forwarding,router remote access,I do not know. Direction reqd.
++I dont know...how can i get this Public IP,,it quite keeps on changing & if so,,,how to set up.?.? :-(
So this seems like a question of 2 parts - but overall you're going to have to become familiar with your routers status page. It should allow you to do port forwarding (which you will have to do) and may help with your IP changing.
Finding your Router Status Page
Your router status page is usually available from one of these two urls:
http://192.168.0.1
http://192.168.1.1
Hopefully one of these will take you to a web page, where you can configure things- if neither do then you're going to have to find out what the right address is - this should be the same as your default gateway so you can follow these instructions: https://wiki.amahi.org/index.php/Find_Your_Gateway_IP
Port Forwarding
Simply put, for home internet connections you're probably going to use Port Forwarding whenever a device that's not on your network (in this case your phone) initiates a connection to a device that is on your network (your arduino).
This is because when your phone connects it will do so to an internet IP address rather than a local IP address and the internet IP can't specify which device within a local network you want to talk to. If your Arduino were to make the connection you wouldn't need to port forward on your home network.
Within your Router Status page you should find configuration options for port forwarding, without knowing your router I can't say much about where you'll find them but they're usually obvious - once there typically you can pick a port or range of ports you want to forward and which IP address you want to forward them too. Judging by your question the port you want is 80, the default one for web browsing - the IP address you want is the internal IP of the Arduino which seems to be 192.168.0.177.
Once you save that you should be able to make connections to your Arduino from off your network but you've still got your IP issue left.
Dynamic IPs
You're quite right you'll need your public IP to connect, this can easily be found from within your network by going to a site like https://www.whatismyip.com
However as you've mentioned, your IP changes quite a lot, so if you don't want to keep looking it up you've only got a couple of choices:
Pay for a static IP from your internet service provider (if they offer this)
Use a dynamic DNS updating service
Probably the most well known amongst those services is DynDNS though there are free alternatives, it's worth remembering that you may be getting what you pay for and I'd perhaps look for recommendations from other StackOverflow users on which to use.
In terms of the actual updating you have two options, the easier one is to install a client on a supported computer which will periodically update your IP. Alternatively, some more sophisticated routers have Dynamic DNS updating built in and this would also be accessible by your router status page, which you're hopefully already a pro at rooting around in.
yes you need public ip of your router as your both device is not in the same network.
Im currently developing a number of online applications with mobile friendly interfaces and would like to test them on my mobile device without having to upload (having problems with my internet connection)
Ive researched and seen there's a way it can be done with static IPs but since my internet connection requires an automatically assigned IP. Can this procedure also be done with a dynamic IP
My nachine and device specs are
Windows 10 64bit
Android 4.4.2
Xampp/Apache
Thanks in advance
There are two ways of achieving this
1) Server behind router
In this approach, you simply use your home/work Wi-Fi to connect to the server, hooked in to the same network. Later on, buy a domain/sub-domain and publish there.
2) Server beyond router
This will require some hacking in most cases. There are websites out there that provide dynamic DNS options. Almost all after-market router firmwares will support registering on to (many of) such websites. And then do port-forwarding to the server behind the router. In essence, you're asking for someone on the outside, to redirect traffic to (your) server, which is on the inside(behind the router).
I'm aware it's been asked before (with limited or no solution) but I haven't seen any recent updates and I think my scenario is unique so I'll start a new thread.
I have a Raspberry Pi and it's functioning as a hot spot among other things. By design, DHCP isn't handing out a default gateway. My use case is one or more devices interacting with the Pi as a server.
One of the connected devices will be a mobile device(edit: running a custom app of my design which is part of the total solution), and that device will maintain its cellular connection, not for tethering or routing but so that the application can access internal and external resources simultaneously.
Currently:
IOS: This works exactly as I expect on IOS - it senses that the WiFi network doesn't have a default gateway and sends external traffic over cell.
Android: This doesn't work at all. Android stubbornly sees WiFi connected and disables cellular, even with no default gateway.
Windows Phone: Kind of a hybrid. Both networks stay up but my scenario has a DNS entry in public DNS, and a public site links to a resource on the Pi. If I link to the resource directly using the WiFi IP address of the Pi, it works fine (although this causes other issues related to security). If I link via a FQDN, I'm actually not sure what's going on. It doesn't resolve from the web browser although every networking utility I've installed on the phone for troubleshooting correctly resolves the FQDN to the Pi address via DNS.
Hope this makes sense. The question: How can I enable this functionality across the board in 2015? :) For my purposes, the Pi as a private nonroutable hotspot works better than WiFi direct or Bluetooth. And remember I'm not asking the phone to ROUTE; I need my custom application to be able to simultaneously connect to the Pi and to the public Internet. I want all the phones to do what IOS does in this regard.
My current scenario is the Pi hosting a web page (among other things) and that's my preference, but can this even be solved natively?
You say that this is not a tethering or routing situation, but if you think about it, it really is both.
It is routing because the traffic from the phone needs to be routed to one of the two interfaces. There may not be routing through the phone, but it's still a routing problem. Fortunately, it seems that the routing part is working on all three platforms.
It is also an unusual form of tethering. The only differences are that traffic does not originate from the Pi, but from the phone, and that the Pi rather than the phone acts as the access point.
Thinking of it in terms of tethering is important because it shows that the Android CAN have WiFi and cellular active at the same time (at least in hotspot mode, but probably also in client mode). In this respect, my answer isn't complete - I can't tell you HOW to accomplish that.
As for the Windows phone problem you mentioned: in order to troubleshoot that, first identify where the DNS server is located that knows about the Pi's FQDN. Does a public DNS server know about it, even though it is obviously on a private network?
There are two possible explanations for your observation:
There is no public DNS server that even knows this FQDN. In that case, IOS is probably using something like mDNS to locate the Raspberry Pi.
There is a public DNS server that knows this FQDN. In that case, maybe Windows Phone checks the DNS reply for martians and rejects it, thinking that it is an attack.
Either way, what you'd really need is to have two separate DNS infrastructures. One way to do this is to include a small DNS server (dnsmasq maybe) with your app, and configure a forwarder for the zone with the Pi's FQDN to forward to the Pi's IP address (which would have to be hardcoded, obviously). All other requests should go to the normal DNS servers.
Another way might be to not use DNS at all, but use the hosts file instead.
For Android phone you can use application named "WiFi & Mobile Data Switch" (https://play.google.com/store/apps/details?id=com.totemsoft.wifimd). For me it solves the problem of simultaneous connecting to internet (via mobile data) and to local network (via WiFi, internet is inaccessible via WiFi). This applications works ok on Samsung Galaxy A8. I hope, my comment helps to somebody.