If I know the mac address wlan0 of an Android device, you can send a text message to this device even if the device is connected to a network other than mine?
No. MAC addresses are only applicable for a local LAN through switches, and cannot be used for addressing or routing by layer 3 routers or outside a local network. However, on an IPv6 enabled network, you can directly use the MAC address using a link-local address, or you may use a direct TCP connection if there is a program listening on the device, and you know the IP address and port.
Related
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'm developing multiple applications which need to communicate with each other via socket. First I need them to be able to communicate on localhost. So when I'm running both of them at the same time on my phone they can communicate (I know that there are easier ways to do this on the same phone but in the future they will run on separate phones).
My code for socket communication is very similar to this: link
Difference is that my apps are running this as foreground services.
I've set the ip for the server on the client to 127.0.0.1 but they just won't connect (not in the emulator and not on real phone). What am I missing?
UPDATE:
I've found an easy way to get the device own IP address, so instead of localhost I use this (with www.google.com domain): answer to "java InetAddress.getLocalHost(); returns 127.0.0.1 … how to get REAL IP?"
Maybe it's not too nice but it works.
You'll need to set the local IP address of each one, so they can communicate within your LAN. So use an address like 192.168.1.X. Both if you're running your devices as virtual or physical, you may easily know the local IP address they have accessing your router's web interface and seeing their bound IPs.
I have searched the web for this with no success.
This is my problem: I am developing an app that reads data from arduino connected with Ethernet shield.
I can connect to it on the internal network (home network) or through the Internet.
The problem is I need to know if the arduino is present on the local network and if not then look for it on the external ip address.
I have tried to use the ping function but it’s not working. Any help would be appreciated.
I presume you know the IP address of the arduino?, have you tried putting your pc\laptop onto the same subnet as the device, e.g. if the arduino has an IP address of 10.254.103.20 you could change the IP of your laptop\pc to 10.254.103.21 and then try pinging it?
Well for one thing, if your router supports NAT loopback (most do, but you may have to enable it) you can always just connect to the external IP address, regardless of whether you're on LAN or WAN.
Cheers,
When I turn on Android Wifi Hotspot, Others join into my network and get Ip addresses.
How's the mechanism of distributing IP addresses between my phone
and clients ?
So is there any methods(Java, Android) or any files in the Phone
system that I need to config to change My Ipaddress(As a Server
Ipadress) and DHCP IP range ??
I need to send messages to Android phones through P2P on 3G connection.
Sending and receiving works perfectly on lan ip addresses(on wi-fi) but not on 3g or 2g.
On 3g I send a message but it never appears on the other end of the line.
Can anyone tell me how to make a connection ?
What port to use ?
Thanks,
DataSmith
DataSmith, what you refer to as internal and external IP address is most probably private IP address and public IP addresses. Private IP address are valid only on the lan where the device is located. This is why you can connect to other peers on the LAN.
However, there is no way you can connect alone to peers on other LANs (unless they have a public IP address on their LAN, which most probably is not the case). You need to learn about IP address translation and NAT traversal to achieve this. You can check the Practical JXTA II book available online for reading at Scribd.