What is required for direct TCP\IP connection? - network-programming

I want to write an app, that establishes direct TCP\IP connection between two devices over the internet.
I have a server to exchange IP addresses and ports, but is it enough to establish a connection?
How to handle cases, where both devices are on the one IP (connected to the same Wi-Fi hotspot)?
Also, I don't understand how open ports on the device could be accessible without port forwarding settings on hotspot? Is there any range of ports open for apps usage?

You are correct about port forwarding for most cases.
TCP/IP is OSI Layer 4 protocol. You need to be able to send data to the sever application with a known IP address and port number. Now when on the internet, this can get more complicated because you normally do not directly interface with the IP address that the rest of the internet reaches you at. This is your public IP address. The modem you have from your ISP likely implements a NAT
, which turns your private address into your public address. You modem will block all TCP SYN requests unless there is forwarding rule specifically for it.
This is just the typical case, you can also look into setting your modem up for DMZ mode and even implementing your own reverse proxy like nginx.

Related

Objective C - Checking that IP Address is part of network

How do I check that a device with a specific IP Address is still part of my network without searching for all the IP Addresses that I am connected to. Is it possible to ping an IP address of a connected hardware directly?
IP address is just an identifier, i.e. a number. Using that number you can try to reach a device that is assigned to that number by your network infrastructure (like network routers).
You say that you have some
IP Addresses that I am connected to
If you are already connected to the device's IP address using TCP, HTTP or any other protocol that has long-running connections, the easiest is to just check if that connection is alive. If you can store all your connections in a hashtable (or map/dictionary) and searching would be very quick.
If you are not really connected, a good way to solve this would be to implement a ping/pong (aka ECHO) scheme: when you send a network packet (or request) with some data and expect that data to come back to you within a reasonable time interval. This could be based on ICMP or your own custom protocol.
Alternatively you can implement a "heartbeat" scheme (or keep-alive, see also: https://serverfault.com/questions/361071/what-is-the-difference-between-keepalive-and-heartbeat , Do I need to heartbeat to keep a TCP connection open? , https://en.wikipedia.org/wiki/HTTP_persistent_connection ), where each device sends a periodic "I'm alive" packet do your side.

Using Twilio to make/receive calls via Cisco SPA504G IP phone

Looking to place calls using our Cisco SPA504G IP phones through Twilio. We have 4 phone lines/numbers with Twilio and we want to use them to place and receive calls on physical phones.
Edited Question:
I found an interesting post in here: https://ertw.com/blog/2013/11/05/using-an-ip-phone-with-twilio/
This where my steps in order to get the phone to ring but I could not hear voice :/
I just bought: http://www.amazon.com/Grandstream-GXP1620-Medium-Business-Device/dp/B00VUU8EZM
Connected phone to my router. I am port forwarding all traffic in the ranges from 10000-20000 to the phone. I am also port forwarding port 5060 to the phone.
Uploaded the following xml file:
<Response>
<Say>Testing</Say>
<Dial>
<Sip>
sip:line1#24.51.221.98
</Sip>
</Dial>
</Response>
that can be found at: http://antnam.com/voip.xml
I called my internet provider and now I have a static IP address so that 24.51.221.98 never changes.
I configured my twilio number (855) 804-0420 to execute a GET # http://antnam.com/voip.xml
When I call (855) 804-0420 I can hear the phone that is connected to my router (voip phone) ring!!! So good news I am able to call the phone I purchased on step 1!
Once I answer the call I am not able to listen to voice :/ . What could I be doing wrong?
In summary everything works great I am just not able to listen to anything. It is as if the call is on mute. Am I missing to open more ports?
It sounds like this may just be a NAT traversal problem; if it is please move or remove this question, as this would only be relevant if you were programming this client. There is a ton of info out there about this issue (for example here is an excellent article that comes up as the first result when I google "voip nat traversal"), but here's a quick summary:
Why NAT causes a problem for VoIP
Most VoIP protocols use a data stream on one port (e.g. 5060 in this case) to negotiate connection information that includes among other things a socket (IP address and port) to receive audio/RTP traffic; there are 2 things about this negotiation of a socket that might be unexpected:
It can be any IP address and port combination, not just one that is on the VoIP device itself. So you might have for instance a VoIP server that negotiates a socket on another host that is not part of the SIP dialog, and which might be behind a NAT
The negotation is done at the OSI Application Layer (Layer 7), so it is normally untouched by the NAT process, which operates at Layers 3 and 4
How to diagnose missing audio due to NAT
If you're able to get packet captures (ideally on both WAN and LAN ports, so you can see your VoIP device's traffic before and after NAT), you can see the problem in action: just look for the packets containing SDP payloads (e.g. if you're doing SIP on UDP 5060, just filter for that port and you will see INVITE requests and 200 OK responses that contain SDP payloads); drill down to the c (Connection Information) and m (Media Description) lines, which should look something like the following:
c=IN IP4 192.168.1.114
m=audio 6094 RTP/AVP 0 8 101
If you're seeing something like this going out your WAN port, it means your VoIP device is requesting to be sent audio on 192.168.1.114:6094; the IP address is a private address and cannot be routed over the internet; the port is just one I picked randomly, but the one you see needs to be open and forwarded to your device
How to fix it
There are various solutions to this problem, which all come down to rewriting the private IP address that your device is giving out into the public one that your device's traffic is being NAT'd out on, so that when the remote device parses the Connection Information line in the SDP, it has a valid, publicly routable IP address to send the audio traffic to, and a UDP port that is NAT'd to your device. Sometimes the VoIP device itself can handle the rewriting (e.g. you can either statically tell the device in its configuration what its public IP is, or it can discover it from a protocol like STUN), sometimes the rewriting is done by the firewall/router that is doing the NAT (there are various names for this, like SIP ALG or SIP Fixup).
Unfortunately due to the variations in NAT implementations across various routers and firewalls, no solution can be guaranteed to work 100% of the time; and if you have multiple devices behind the same firewall, having it do the rewriting will only work for one of them.
In your case:
You mention 2 different VoIP devices, a Cisco SPA504G, and a Grandstream GXP1620. The datasheets for both devices say they support STUN, so I'd start looking in its config for the STUN settings or anything else that references NAT traversal. Also, make sure that the ports you are forwarding to the device are the ones that it uses, this is usually just another item in the config, called something like "RTP base port" or "RTP range"
I would also ensure that you nat transveral enabled with stun using a public stun server such as stun.sipgate.net
Note: STUN operates on TCP and UDP port 3478.
This is required as the phone needs to send the external ip in the sip packets. Without stun it will send the internal ip and the far end sip device will attempt to send the data there.

How can I access WiFi router configured in LAN?

I have a LAN setup in my office which has 10.10.14.0/24 network and internet connectivity. I have one port of the switch connected to WAN port of my Wifi Router. So, one IP address 10.10.14.x has been assigned to router on WAN port. Internet seems to work fine when any mobile is connected to WiFi router. From my mobile, I can access WiFi router on 192.168.1.1. So on Wireless front, I have 192.168.1.0/24 network.
I have a PC in 10.10.14.0/24 network having IP address 10.10.14.y.
How can i login into Wifi Router (10.10.14.x) via PC (10.10.14.y)?
Do you want to access the administration interface ?
I don't think the Router allow to display the interface from a computer connected From the WAN port, since it's "The outside".
You need to define Port forwarding, if your router has a static ip address or the ip is known, you could add it to the port forwarding rules.

Client server over wireless network

Is it possible to set up a simple client server application to send text and other data over a wireless network in a LAN situation between two computers without setting up any network shares? By just knowing the IP address?
Yes. WiFi is just like any other network, you use TCP/IP over it to implement any network protocol you like.

Getting IP addresses of the PC's available on wifi network in android

I am able to establish connection between android and PC via Wi-fi. But this is done by hard coding the the IP address of the PC (server) in the android program. But I wanted to get IP addresses of the PC's available on the Wi-fi network programmatically. So please let me know how to scan for PC's on the network and get their respective IP address.
can you not multicast a UDP packet on the network which the server listens for and responds to with a packet containing the ip address of the server in order to set up the connection?
You should be able to find help on that topic, with some options here here and here

Resources