I have some iOT devices , currently i am creating tcp socket connection one by one to all of the device, all devices are connected to my local wifi.
Is it possible to send one command to all devices at a time, like a broadcast pattern? Is it possible to send and receive broadcast message in android?
Yes you can send broadcast message to all your device connected on to your network. But for that you need to understand broadcast IP address of your subnet / net. Which is something like 255.255.255.255.So get your subnet mask first and your ip address. Once you have both find your NETWORK Address. Do a search how to calculate network address from IP address and Mask. Once you have Network address do a search about how to get broadcast address. Now when you have broadcast address you need to create DATAGRAM socket (UDP) with the broadcast address. All your IOT devices must be listening on that UDP socket. So once you send your data to this UDP socket all your devices on the network will receive that message.
Check here for java based implementation
Check here for how to get broadcast address from ip and subnet mask
Related
How we can read or receive Broadcast message in Android WiFi network sent from Same network (Router) using UDP packets . I am trying to use MultiSocket and socket for receiving Packets, but I am not able to get Broadcast message sent from Network.
Also I am testing the broadcast message Wireshark. Its working fine, but I am not able receive packets on Android Device.
So my question is how we can achieve this?
Thanks in advance!
Complete novice with this topic - struggled to grasp an understanding.
Two devices - Device A, Device B(Laptop)
Device A - IP Address 192.169.0.120
Device B - IP address 192.169.0.121
Device B(Laptop) is connected to WiFi, and to Device A through Ethernet cable.
I have an embedded app in Device A, which i access though web browser on Device B(Laptop), on Device A's IP Address.
Is it possible to make this IP address public - for instance my mobile to pick up Device A's IP address?
I've looked into VPN's (hamachi) and port forwarding. is this the right way to go?
image of example setup
You can use ngrok to obtain the public ip address. This will basically expose your machine as public although it is in private network.
reference : https://ngrok.com/
You can't connect from outside the network using your local ip (192.168.0.120). Check out this topic if you want to know how to grab your external ip:
Getting the 'external' IP address in Java
I've tested the program locally using a program called "Packet Tester"
I downloaded UDP Receiver/Sender for my mobile. Using the java program on my computer I was able to send packets to the mobile server and it was working great. I just typed in the mobiles IP address and the port number it was listening for.
When I tried running my UDP peer to peer on my Laptop and Computer they could not chat at all.
Does anyone know if it is to do with the fact the same router is being used or what not. It should not be since my mobile is receiving messages from the laptop and computer. ]
The Java app can retrieve UDP packets locally, but not from the laptop or mobile. The mobile can retrieve udp packets from the laptop and mobile. The tests show confusing results which have lead me to a wall.
I would appreciate what your thoughts on this are.
Thank you.
The problem might be because of Network Address Translation done by the router.
I believe you are sending packets to correct IP address but the port is not correct. The port to which you might be sending the packets is the local port to the machine.
You need to send the packets to the port assigned by the router.
When the packet goes from a computer A to computer B through the router, the router maps the local port of computer to some random port.
So, if computer B needs to send a packet to computer A, then the computer B needs to send it to the IP:port assigned by the router. The router will then forward it to the local IP:port of computer A.
I suggest first understand how this mapping is created when UDP packets travel through a router within or external to the network. Read about Network Address Translation, UDP holepunching.
These source may help:
Network Address Translation
UDP Hole Punching
RFC 4787 NAT Behavioral Requirements UDP
RFC 5128 P2P across NAT
I'm trying to connect my pc to my android phone via WIFI..
But the problem is anytime I disconnect my phone from WIFI and turn it on again
I'm getting a different IP address so my pc doesn't connect until I change the IP address to connect to.. Is there any way to get the correct IP address of the phone?
That might be a router settings issue. Have you ever heard of "DHCP Reservation"? Most routers support such an option, which enables the router to memorize an IP to every distinct client ever connected and then to assign this ip to the respective client every time it reconnects.
Check your router settings / documentation for this option.
Here is a link, which could help you with your further investigation:
http://lifehacker.com/5822605/how-to-set-up-dhcp-reservations-so-you-never-have-to-check-an-ip-address-again
I have a SMS Sender & Receiver MIDlet with MessageConnection created in Client mode for sending SMS to a particular destination on a particular port. This destination is sending back an ACK SMS without any port number set, to my device inbox. My MIDLet is listening on a same port number used for sending SMS. Problem is MIDlet is unable to listen & process this SMS. The message always goes & sits in the device inbox. Is there any way to listen to SMS without any port number? or route the SMS to the MIDlet?
No. It is not possible to receive SMS on the standard port with JavaME.