Since you are developing/using a custom application it is very hard for me to tell you what is going on. Perhaps it would be best to start with something simple, such as connecting to a web server or SSH connection to make sure that the basic functionality is there. I typically use nginx or lighttpd on a Pi for web connection testing. These packages include a default web page so you don't have to do anything else to get a basic web server running for testing.
Another debugging strategy is to make sure that the client-server connection works over the LAN before introducing the remot3.it connection.
Finally, just to be clear, the port number used on the Pi for the server (e.g. 22 for SSH) is not going to be the port number that will be returned by a connection API request.