Those applications 'poke holes' in the firewall by sending out packets, usually UDP, to open holes in the firewall. Most firewalls/routers will open ports for traffic if the traffic is initiated from behind the firewall.
That's how Skype works (minus proprietary encryption): You install it, and it automatically pokes a random hole in the firewall to connect to another node, Once that connection is established, it records that port number as active for this session, and that's that.
PS - Are you trying to develop an application? StackOverflow.