Its not possible (as far as i know) to pass packets between 2 clients that do not share the same network without referencing port number. and it does not matter whether it is TCP or UDP.
every data that you sent from your computer, is converted and wrapped as a packet - always!
it does not matter what programming language you are using because it happens in the Network and Transport layers
according to the OSI model
a network packet must contain:
- source IP
- Source Port
- Destination IP
- Destination Port
a little analogy i can think about for better understanding:
Imagine that you want to visit a friend in a foreign
country.
You know which country to fly (external ip address)
and you know your friend address in this country (internal ip address).
but when you arrive you dont know which train to take in order to reach your freind`s home (port number).
so without knowing the exact train (port number) there is no way that you will be able to visit your friend.
if you go and ask the information station (the router) in the airport and this train number realy exist (the route map / port forwarding configuration)
they will direct where is the train that you need to take and you will be able to visit you friend.
that is the reason why you must configure port forwarding in the router - in order to update the route map