Get IP of Android for P2P connection - java

Would it be possible to get the IP of Android Phone for P2P connection, Actually i want to connect two android Phones via Sockets ?

I believe you'll need a central server which helps with peer discovery. That's not all even getting IP might not be enough you'll have to work around issues like Net traversal ..this may help Android: NAT Traversal?

Related

Is it possible to access lan when using vpn?

I'm building an app, and I need to access some data in lan with a given address(Say 192.168.11.222), I use HttpUrlConnection to do my work, and this is just fine when I did not launch a vpn connection using other app(Say shadowsocks android), but when I using vpn established by other app, I just get an exception
java.io.IOException: unexpected end of stream on com.android.okhttp.Address#9727cf6d.
I tried using openConnection(Proxy.NO_PROXY), and that just does'nt help, anyone know how to figure it out?
Since I can't close vpn in some cases.
Thanks in advance.
As far as I know if you use a VPN Connection you will get a WLAN instead of a LAN, so the device connected to a VPN will have access to the machines of your LAN and the network of the VPN. The problem here is when the network of LAN and the VPN network are in the same IP address range. If some machine in your LAN has the same IP address than some machine in your VPN network it will cause conflicts on routing the packages.
So is it possible to access lan when using VPN? Yes, but you have to take into account the previous explanation and be sure that the machines won't have the same IP so you don't have problems to access resources

Accessing remote device in android

I want to access remote device(PC) connected in LAN or wi-fi in android device,using ip address device username and password.is there any way for doing this?
what will be the right way for starting this.
Thanks in advance.
You can simply use Socket to do that, just set up a ServerSocket on your PC, let the android open a TCP Socket connection with your PC and sending data vice versa. One thing, this will only apply in the SAME wifi or network, you can't do that on 3G due to the NAT restriction.
Check out this link: http://examples.javacodegeeks.com/android/core/socket-core/android-socket-example/, you can set up your Server part on Java, not neccesary to be Android. Hope this helps.

file transfer using p2p connection in java

i want transfer files using p2p connection. There will be a server or any common place to share both A and B computers information for establishing the connection.
I've created p2p connection using LAN.But my question is - for internet how can I detect the IP addresses of the 2 computers for socket programming ? or any other option so that I can transfer files between two computers which are connected with frequently changing IP address ?
Thanks in advance.
JXTA is a framework that can do that for you. I wrote a book called Practical JXTA which is available for reading online at Scribd. It contains complete code examples. You want to work with release 2.6 or 2.7.
If you don't want to use a framework, your central peer should be able to read the NAT-translated address of your remote edge peers, when they connect to it (see Socket#getRemoteSocketAddress()) . But that won't help with TCP (to make it simple). If you use UDP, then you stand a chance, because once a UDP hole is punched in a NAT, many peers can (usually) connect to it.

Networking in Android

I know in Android you can do networking and I've done it but I've only been able to do it when the phone is connected to a WiFi network. I'm wondering if is there a way for my Activity to connect to my server without having an active WiFi connection.
It would kind of be a pain to market my game if you must be connected to a WiFi network in order to play with other people. When I tried connecting to my server without an active WiFi connection i get this error:
java.net.SocketException: No route to host
All answers are welcome. Thanks in advance!
In order to make network calls and use network resources, you need to be connected to a network: either with "cellular" data, such as 3G or EDGE, or WiFi.
However, Android should handle most this behavior pretty well behind the scenes.
For more information, check out Android's Connectivity Manager, Content Provider, and Java's Sockets.

In Java, how can I test for network connectivity without using DNS?

We have a Java application running on a portable device and the JVM we're using (CReMe) appears to have a bug where it caches negative DNS lookups, even when we tell it not to. Thus, when we try to make a connection to our server and the DNS lookup fails because the network connection isn't established yet, the application is stuck because it will never perform the lookup again, even when connectivity is restored.
We've tried testing by opening a Socket to a hard-coded IP address, but obviously there's no guarantee that a given IP address won't change in the future. Can anyone suggest another way to verify that we have network connectivity?
You could have a list of IPs and try to open a connection. They could be IPs of machines on your LAN or they could be Google or Facebook's IP.
If you can't connect to any IP on the list, you can assume the network is down.
When the network is up, you can update the list with a DNS lookup.
You could try custom DNS client like dnsjava.
Maybe you can try to use the DNS servers of Google? Doubt they will ever change, and pretty sure they are usually up :)
8.8.8.8
8.8.4.4

Categories