Which low-number network ports required in iOS apps? - ios

Are iPhone apps are free to access any low-number network port required? Is there any thing called low-number network port in iOS ? Is this true?

You can check this: TCP and UDP ports used by Apple software products
As it's written at the above article, Many of these ports are well-known, industry-standard ports. You should use a known port only for its purpose (for example - use port 443 only for https).
If you have your own custom protocol, use a port that isn't one of the common ports. For that - choose a big number. You might also run a test to check that the port you chose is not already been used.
In addition - see this thread
How to select a static port number for a custom app?
And finally, you can also check here, where you can see a lot of port numbers usage: https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml?&page=1

iOS is based on Darwin UNIX, so I would use that as a rough guide to what's acceptable with regard to selecting ports to communicate on.
Here is a list of well known low ports.

Related

Wanted to know the meaning of source and destination port. (wireshark)

On my package 1, under the info it says (source)54841 > 80(destination). May I know what are these terms mean and why these particular ports are being used. i know that for tcp, they uses 80 for destination port. but is there a particular reason? Thank you
In fact, there are two questions with two different answers.
Firstly, you have to be exact: The port definition is part of the Internet Proctocol (commonly called TCP/IP) application layer. The tcp protocol is a protocol of the underlying transport layer, so the definition / use of port 80 is not defined for tcp, but rather for the http application protocol (while the actual port usage takes place in the transport layer).
Regarding the destination port, you nearly gave the answer yourself: For well defined application protocols, there were defined well known ports. The list is maintained by IANA (https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml). Usually, the ports were defined in the privileged low number range (up to 1024). When that range became to full, there were also higher port numbers assigned.
The reasoning behind the well defined port numbers is, that services can only listen on specific ports, and if the numbers were known by convention, you had to memorize them along with the server adress. For your example, HTTP, that means, that if you start a request for http://www.example.com, your browser (or other software) knows that http usually uses port 80, connects to that port to get the html page. You can still run http servers on different ports (say, 12345), but than, the user had to enter http://www.example.com:12345 to reach the server. You can see that using well defined ports is helpful here.
For the source port, it is a completely different story. As transport layer connections usually use ports for multiplexing/demultiplexing on both source and destination, every connection must also have a source port. The lower port numbers can not be used for this purpose, as on one hand, they are often used for listening services, and on the other hand, their usage is privileged on some operating systems, so normal users cannot use them at all. For this reasons, IANA assigned the port range from 49152 to 65535 (2^15+2^14 to 2^(16−1)) for that purpose. Most operating systems will select one of this ports for outgoing connections source port. The selection is, however, short lived - when the connection is closed, the port is released, and the next connection can use an other port.

Which port range should I use to open a random port?

I'm writing an application that is broken in two parts, the second should open a random port the first one uses to communicate to it. Which port range should I use to avoid collisions in most platforms (Linux, *BSD, even Windows)?
It is operating system specific. On Linux, you might want to avoid ports listed in /etc/services, see services(5) and you want to avoid privileged ports (below 1024).
As a guess, you might try in the 10000-30000 range first.
Read also about tunnel brokers.
I can suggest a solution in such a way that picking a free ports available randomly.
If you are using python you can go with this:
sock.bind(('', 0)). The OS will then pick an available port for you. You can get the port that was chosen using sock.getsockname()[1], and pass it on to the slaves so that they can connect back.
On Linux, do not choose port by yourself. If you bind on 0 port, linux kernel will choose free port for you.

What is the significance of port number in localhost?

Different websites uses different ports, like Codecademy uses localhost:8000 in its AngularJS and Ruby On Rails tutorials. So, I want to know what is the use of this 8000 in localhost:8000. Thanks in advance :-)
This is not specific to one framework, it's a much lower level. From Wikipedia:
In computer networking, a port is a software construct serving as a communications endpoint in a computer's host operating system. A port is always associated with an IP address of a host and the protocol type of the communication. It completes the destination or origination address of a communications session. A port is identified for each address and protocol by a 16-bit number, commonly known as the port number.
Specific, well-known port numbers are often used to identify specific applications and services. Of the thousands of enumerated ports, 1024 well-known port numbers are reserved by convention to identify specific service types on a host. The protocols that primarily use ports are the Transport Layer protocols, such as the Transmission Control Protocol (TCP) and the User Datagram Protocol (UDP) of the Internet Protocol Suite.
In the client-server model of application architecture, ports are used to provide a multiplexing service on each port number that network clients connect to for service initiation, after which communication is reestablished on another connection-specific port number.
I assume, there's a task runner like grunt or gulp serving the page via BrowserSync (or similar). They use a different port than 80 to not interfere with an already occupied port by a local web server (apache, nginx,...).
This is just a port which rails is listening to. It depends on how you configure your rails server, and, IMHO does not mean anything useful. Sometimes you have to assign service to a different port because default port is occupied by some other service. Sometimes it is done by security reasons, so the hacker from outside world has to know the port you are using. But it's actually not very hard to know
Just to add to what the others have said: all network communications require an ip address (which can be got from a domain name like www.google.com) and a port number. However, if a port number is not supplied then the http server uses the default: this is usually port 80. So, if you were to go to "localhost" without a port, you are effectively saying "localhost:80". Your computer probably doesn't know what to do with this. If you say "localhost:8000", and there's a rails server there, then it will handle the request.

Send UDP from iPhone to iPhone via WAN

In my recent app I managed to send data (mostly audio) via UDP in my local network (WiFi) to other iPhone. And now I need to do this same but in WAN. Can You guys please point me in the right direction where to start? What I need to achieve this?
I'm using GCDAsyncSocket to manage sockets. I believe that I have to got server, where I can keep IP addresses of both devices.
Also, how can I connect to device behind NAT/Firewall? I'm guessing, that I need to have public IP address (scrapped for instance from http://checkip.dyndns.com/). And then do I need to traceroute? Or NSLookup? Or piggyback? Or do I need to use UDP hole punching?
I know it's a lot of question, but if you can just point me to the right technology, I would be very grateful.
To achieve a communication between two participants behind a NAT you could use Hole-Punching like you mentioned it. This is explained quite well here: http://en.wikipedia.org/wiki/UDP_hole_punching#Flow
Basically a Server with a Public IP and Port is used to share the Port-numbers of the iPhones.
But a NAT may use a different Port for every different IP the iPhone talks to. So if iPhone1 sends data to the server the NAT uses port X, but if iPhone1 wants to send data to a different IP the NAT may choose port Y. (See http://en.wikipedia.org/wiki/Network_address_translation#Symmetric_NAT)
To overcome this problem there is a protocol called UPnP and the lesser known NAT Port Mapping Protocol.
I am not well versed in UPnP but maybe someone else can provide some information on that.
The protocol NAT-PMP enables you to dynamically request an external port to be forwarded to your device. See http://en.wikipedia.org/wiki/NAT_Port_Mapping_Protocol, RFC 6886 .
This allows you to "predict" your external port and establish connections over NAT.

How to handle firewall restrictions while building chat apps?

I am building a simple chat application using a jabber based server. The clients are expected to connect over port 5222. But, when i was testing my app, I found that in some networks access is limited to port 80 or 8080 only.
I have came across a couple of solutions:
a) Use BOSH - but found it to be slow and flaky on mobile devices.
b) I was just wondering what if i make my jabber server listen on port 80 - (Not sure what would be the implications of this!)
I wanted to know your thoughts on above solutions and know how to make my app universally accessible like other chat applications like gtalk , fb-chat etc.
Edit:
Also, would there be any other firewall restrictions that i might be missing?
Use BOSH over HTTPS (port 443/tcp). Getting BOSH implemented well is a little tricky, but it can certainly be done. Use a different XMPP library.
Otherwise, use port 443/tcp, and use the old-style TLS-handshake-first mechanism that we used to use for encryption, rather than Start-TLS. Some network middle-boxes will mess with your traffic on port 80/tcp if it doesn't look like HTTP. Likewise, some middle-boxes will not allow your connection on 443/tcp if the first several network packets don't look like a SSL or TLS handshake.

Resources