There are 2 android phones,
They want to communicate directly with P2P via socket connection.
Both phones know each other's IP address'
Both phones are behind different symmetric NATs
You have root access to both phones.
You are allowed to install additional software on the phones
No TURN server should be used in the communication path
how to achieve above scenario
Related
I have java programs for my client and server, and they work fine within the same wifi network. But I need the clients to be able to connect to the server from the open internet. In questions like these
How to connect client and server with the help of ip address which are connected to internet through different wifi?
https://coderanch.com/t/667020/java/Socket-connections-networks
the solution is to manually reroute a port to the server from the router, making it open to connections from the outside. Is there a way to do this with just software on the server? I don't understand why manually dedicating ports is necessary since of course other applications on my computer (like games) that I install communicate with their servers back and forth without me having to manually go in and flip switches.
How can I achieve this with just software running on my server?
If there isn't another way, how do other applications communicate openly without manual router changes, and will opening up ports through my router result in security issues?
You would need to change the architecture of your application. Currently, your server is behind a firewall which blocks connections from the internet - you want this! If you allowed all traffic from the internet to connect indiscriminately to your server, it would be very vulnerable to attack.
Other applications install and communicate without port-forwarding because the developer provides a server on the internet to act as a proxy between clients. The client connects out to the internet which is generally not blocked on home networks. Internal connections going out are considered less harmful than connections coming in.
I am working in an application that requires an Android device to connect to a Wi-Fi network. This Wi-Fi network does not have internet access - it is a Wi-Fi network created by a end-device and used only to communicate with it using TCP sockets. I would like to be able to access the cellular data internet connection on the Android device WHILE communicating with this device over Wi-Fi and I wanted to know if this is possible.
Here is what I know so far:
It is possible to get list of all interfaces available on the device and their corresponding IP addresses via the Android NetworkInterface API.
There is an option in the Developer Settings in Android to keep cellular data interface up even when Wi-Fi is connected.
It is possible to provide the local address for the Socket to bind to when creating a Socket()
With these in mind:
When I am connected to the Wi-Fi network with the SIM card in the device and LTE enabled I am able to get wlan0 interface with a "local" IP address in the format 192.168.x.x and rmnet0 interface with a non-local IP address.
However, depending on the device, I am only ever able to access ONE of them at a time.
For example, on a Pixel 2 XL running Oreo 8.1, LTE Enabled, Cellular Data Always On enabled:
I am unable to communicate over Wi-Fi AT ALL. Any Sockets created with the Wi-Fi local address time out.
On a Galaxy Tab S2 SM-T818W running Nougat 7.1, LTE Enabled, Cellular Data Always On enabled:
I am able to communicate over Wi-Fi but not able access the cellular data interface.
The only way I am able to access the wlan0 interface on the Pixel 2 XL is by calling requestNetwork from Android's ConnectivityManager API and requesting Network with TRANSPORT_WIFI capabilities but this defeats the purpose since now all communication and sockets will be bound only to the Wi-Fi network.
I know that when USB tethering is enabled, it is possible to access devices on the Virtual USB "Ethernet Network" interface which shows up as eth0 with either the wlan0 interface or even the rmnet0 interface by specifying local addresses on the Socket connection calls. It just appears to be a problem with Wi-Fi and cellular data.
I wanted to know if this is an inherent and intended Android limitation or is there a way to access both interfaces at the same time that I am missing.
Appreciate your help. Please let me know if it would be better for me to provide specific code snippets, I wasn't sure since it would make this post quite long.
Best,
I am developing an app in which the first thing i need is how to get devices that are connected to my wifi network or same wifi network .ie ip adress,device name etc.
I don't have any idea how to do that have searched alot but there are no examples available.
I have done one thing that i will ping 255 ips and whichever will respond will be the connected ips but the problem here is that there are virtual ips already assigned to some websites so i need to detect only the real device ip addresses.
I want to do the same thing as done in the app WifiTalkie
Follow Any one of the following:
Way1:
If you mean you want to see all the devices connected to your current WiFi connection (and you are not trying to do Ad Hoc networking), then you are essentially wanting to run a network scanner.
There are a bunch of these around. This one has the source available on github
http://rorist.github.com/android-network-discovery/
Way2:
Refer How to detect all the Devices connected in a WiFi network from Android App
I'm coding an app which consist of two pieces. Desktop and android. There is one desktop and several android devices. (don't know the count.) I want to communicate android devices between desktop with TCP. However, android devices doesn't know desktop's lan ip address.
I thouht 2 ways:
1-Desktop app changes the local ip address on start. So android devices know the ip address. (I coded with that ip address)
2-Desktop app always tries to connect ip addresses (192.168.0.1 - 192.168.0.255) to sent desktop's ip address. And when an android device connect to the network accept the connection then know desktop's ip.
But there is some problems in both ways.
On first, you must be administrator to changing lan ip. So run command as admin with java is a problem. Because if I do this, when user start the program, uac always asks for it.
On second, I think there will be performance issues because of app always tries to connect. Exept this, when android device connect and dhcp gives it 192.168.0.5 , but loop is on 192.168.0.150. So android device have to wait for connection.
Is there a better way than these?
Look at this post Network discovery in Java using multicasting
I think this would be the best way to do it.
The server will listen for a broadcast message from client
the client sends a broadcast request asking for server ip
server receives request and replies back with server ip.
You can use the hostname. If the network is properly configured, the host name will point to the correct ip even if it changes
I am trying to control a Remote Control Car with an Andriod Phone from my PC (over 3g internet)
I'm planning on using a ioio (Which is just a board that I can plug into a andriod phone via USB)
The part I am working on now is the communication from my PC to my Andriod App. I've never made Andriod apps before and I'm a amateur C# developer.
At the moment I am planning on communicating via UDP as I can create a UDP server/client in Java easy enough. (http://systembash.com/content/a-simple-java-udp-server-and-udp-client/)
However I think this may require a public IP address? Which I will not have either on my client or server.
So for simplicty sake, How would you commucicate over the internet between 2 JAVA applications. If you need to stream video from a camera and simple commands.
You don't necessarily need a public IP, you just need some sort of IP with which one device can send packets to the other. For example, you could connect the phone to your home wifi network, and use the private IPs (typically 192.168.1.x) of the two devices.
If you need the phone to be on 3G, and your PC is behind a NAT router (which is typical), then you'll need to forward a port to your PC — this is a configuration setting on the router — and then have the phone connect to that port on your router's public IP.