In addition to the answer of Sergey, if you have already tested code working on your intranet it should work with no problems also on the internet, but same small details have to be checked.
First of all check that the windows firewall is not filtering your access to internet. If so insert your app in the list of exceptions and give it permit ti access internet.
Check the address of your partner on the other side: i.e. if you have an intranet address of, say, 192.168.1.10 consider that
this is not the address with which you are visible on the internet... For the same reason your partner on the other side is not known to you with its intranet address.
To estabilish the communication there a re a lot of means, and it is not so easy to synthetize here, but the main 2 ways are:
1. Create a VPN on which resides your and the remote machine sharing same subnet. In this case the access is made simply using the intranet address.
2. To estabilish an internet connection on public net requires that
at least one partner, the server, has a public address (internet public address) to be contacted by the partner. This is very important because the TCP/IP stack can understand that the address is outside the local subnet and start the message routing through the internet. On the server side you can set the router to direct such internet incoming connection from a specific address and port to a specific local machine (intranet address and port). The local server then sees any incoming connection routed on its local address so can handle them. The translation of messages, or better the routing, betwen the network and the machine is transparently handled by the router. When the client starts a connection it specify as the public address to which it want connect that of the remote router on the internet, then the router will dispatch messages to the local machine accordingly to its network translation table. These functions are normally available on any decent economic internet router.
This[
^] white paper is a good font of info's.