I have local server running in my local network.I want to enable external devices to make request to my local server in this case i am testing with android phone on cellular network.For this I am trying to do UDP hole punching.First I am sending http request from the mobile device to public server to give the public server mobile device's information(IP and Ports) so that i can use them to punch a UDP hole in my local server.But the problem is i am getting NAT public IP & public Port and only local IP of the mobile device but not Local Port.And I just learned that cellular network wont let you use mobile local ports.The question now is how would i accomplish UDP hole punching in this case? If there is anything that i mis-stated please correct me.Thank you in advance
Related
A couple questions.
TLDR is sending UDP broadcast packets on a Wifi network to allow for discovery of a IoT device (Raspberry PI) a conventional practice?
Long version: I'm working on an IoT project for a class. Based on other IoT devices I've used (a Christmas carol lighting system and music player), we decided to utilize an already working application (https://github.com/balena-os/wifi-connect). The way it works is it runs on the Raspberry PI and hosts a wifi endpoint through the RPI's network card that the user can connect to. Once a user connects to this Wifi endpoint on his/her Iphone, a Wifi selection and password entry page appears on his/her Iphone. The user enters the Wifi/password that the IoT device (Raspberry PI) should connect to. The entered Wifi will then be connected to by the Raspberry PI. The user can then connect to the entered Wifi as well and now both the user's Iphone and Raspberry PI will be connected to the same Wifi network.
We decided to send UDP packets to the broadcast address of the Wifi network from the IoT device, so that users connected to the Wifi (via their Iphones) can "discover" the IoT devices IP address by listening for UDP packets. Once the user discovers the IoT device's IP address, they can send HTTP RESTful API calls to the IoT device. I was wondering if the described process is conventionally used.
# script we are using to send UDP broadcast packets
import socket
import time
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
server.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
server.settimeout(0.2)
message = b"message"
while True:
server.sendto(message, ('<broadcast>', 16123))
time.sleep(1)
We tried this setup at a public library, using their free public wifi. However, the UDP broadcast packet discovery process failed. UDP broadcast packets were sent out by the IoT device, but were not received by the Iphone. We're wondering if this has something to do with a firewall. We could successfully send UDP broadcast packets from a Macbook (via a python script) to an IOS emulator residing on the same Macbook, such that the source IP address of the packet was the same as the recipient. Is there a firewall rule such that a broadcast packet sent from IP address [A] can be delivered back to IP address [A] but not to IP address [B].
Also, I didn't mess around with the port number, which might have helped if certain ports were disabled by a firewall. I'm not sure. Help is appreciated. We are both relatively new to this.
DNS-SD (RFC6763) is the a fairly common and standardized way to do network discovery. It actually supports both TCP & UDP services. It was originally invented by Apple under the brand name "Bonjour" for printer discovery.
So yes, it is common to use UDP broadcast packets (via DNS-SD) for IoT device discovery on a Wifi network.
I have 'Socket test v-3.0' software installed on two different PCs.
Using it can create a TCP server on 1st PC and a TCP client on 2nd PC.
When I connect both the PCs on LAN I can establish a connection & can communicate between the Server & Client.
But, When I connect both the PCs to individual Internet connections (Using dongles having different ISPs), I couldn't establish the connection between the Server & Client.
How can I do that?
Please help me out..
The private address 192.168.x.x is address that can be used for direct connection only in your private network. If you want to connect to your machine from public internet you have two options:
Get a public IP address
Configure a port forwarding
Public IP address could be get from your internet provider but it is usually requires some extra payment dependent on your service provider policy.
Port forwarding can be configured at the device at the border between your private network and internet. The device does the NAT (network address translation) between your private network and intenet. Use google if you are not sure about NAT.
Such a device can be your own device like an ADSL modem or a set top box. But such a device could be in the internet provider network. If you own the device then you can configure the port forwarding yourself. Modems usually have a web interface where you can easily configure port forwarding. See the documentation to your modem or whatever you have.
If the NAT device is in internet provider network then you have to ask it to configure port forwarding for you. Before you ask please read something about port forwarding so you are sure what you want to configure.
I use Linphone(http://www.linphone.org/) open source to make a mVoIP android application using Asterisk Server. It is working nicely when the smartphone is on 3G or 4G(LTE) network. However, it failed to register when it is on Wi-Fi network.
Via and Contact info was wrong for smartphone that is on Wi-Fi network.
A = Smartphone on Wi-Fi network
B = Smartphone on 4G(LTE) network
It delivers sounds to B phone from A phone. However, it failed to deliver sound from B phone to A phone.
I traced SIP logs and noticed that phone A tells wrong private IP address(contact) to Asterisk server. It was why it failed to listen sound on phone A.
So, I turned on Stun server, which I have to connect specific stun server, it hardly finds local IP address through NAT. The problem was that Linphone itself cannot find a private IP address of smartphone A that is on Wi-Fi network.
C = A third smartphone on Wi-Fi network.
Another problem that I faced is that an additional smartphone on same Wi-Fi network is not working even though Stun server solved its NAT problem.
Is there anyone who had same issue? and is there a way to solve this issue? Thank you.
You have
1) enable STUN
2) in asterisk set directrtpsetup=no for BOTH peers.
I'm working on an app that relies heavily on P2P, but I currently don't have any SIM cards with which to experiment so I'm testing on a wifi network.
I'd like to know if iPhones on 3G networks are connectable and whether or not I will need to traverse NAT devices.
You're behind the provider's router and your IP address will be something like 10.x.x.x - so you'd have the tell the router, that a TCP connect from the internet to port 9420 should be forwarded to your device. I doubt that they will do this for you.
I want to connect two devices that are in different locations but connected to internet, a computer running windows 10 and a smartphone android. The application is a simple UDP socket to transmit data between them, but I have different scenarios.
1st Scenario. PC with Public IP and Smartphone behind 3G/4G CG-NAT)
The PC opens de UDP socket and the Smartphone connects to the public IP, easy and fast.
2nd Scenario. PC behind a NAT with public IP and Smartphone behind 3G/4G NAT)
Option A) The PC configures a port forwarding to the NAT to it’s internal IP and then the Smartphone connects to that public IP. Easy but not fast because client has to configure the NAT.
Option B) Use UDP HOLE PUNCHING to open a hole on the NAT and then the client connects to it.
3rd Scenario. PC and Smartphone both behind CG-NAT.
Here is my problem, PC sometimes is behind a CG-NAT, maybe because of ISP using this technique or maybe connected to internet using Wifi Hotspot from another Smartphone.
As far as I know, I can’t configure CG-NAT with any protocol (UPnP, PCP, etc…), so I can’t do port forwarding. UDP Hole Punching is neither an option because of the “port randomize”, so the ISP changes my source port when going outside the CG-NAT and this changes for each connection.
I’m developing a project that relies on this, direct connection between a PC and Smartphone without technical details, and working always that both clients have internet, never mind if firewalled, behind NAT’s, etc…
I was thinking about using a 3rd cloud server with public IP to connect them BUT just for stablishing the connection, not to forward all the traffic because this adds latency and traffic costs to my project which are not affordable.
So… is there any technique to give a solution to my problem?
Thanks!