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.
Related
Using tcp sockets, I wrote a server, launched it on a computer. Wrote a client for android. Being in the same local network, I successfully connect from my smartphone knowing the local ip address of the computer and the server port.
The problem is that I want to run this server on multiple computers on the local network, and their local addresses can change.
Need to somehow scan and select an available server in the application.
How is it implemented? What is the special protocol for scanning? Or just try to connect by sorting through all possible addresses and ports?
Is UDP broadcast a bad solution?
Sorry for google-translator!
UPD: I am trying to make a remote PC application. This will not work on the global internet. only local network. Thanks for the answer
I solve it by use DatagramSocket to UDP broadcast to 192.168.1.255.
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
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?
I'm new to networking and was wondering a way to find out from an android phone java app whether there is an application running on any computer on a wifi network it's connected to and a point in the right direction on what to google or a tutorial?
edit: The application I'd be finding would have been made to be found by the android app
Thanks,
Harold
You should use a UDP broadcast. Basically, a server announces its presence periodically on a local network with broadcast packets. A client then picks up on these packets, finds the source and connects to it. A networking library like KryoNet (available for both J2SE and Android Java) makes it much easier.
InetAddress address = client.discoverHost(54777, 5000);
System.out.println(address);
usually application discover their peers in the same network using UDP broadcasts, maybe thats what you are looking for. this requires the app on the lan to listen on a specified port, the phone (or whoever is looking for that app) sends a udp packet to that port on the broadcast address (255.255.255.255), and the app replies with its individual ip address. not sure if that is what you are looking for and if its possible with 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.