This sounds like a port forwarding issue.
To solve this, you'll have to enter you router's web interface. It can be reached on your router's address, which can be obtained using the ip route show
command:
default via 192.168.1.1 dev eth0
In that example, the router's IP address would be 192.168.1.1
.
The procedure may vary depending on the manufacturer, so the best you can do is to search in Google how to do it for your specific model.
Anyways, there should be some setting called "Port forwarding" or "NAT". Use the following info for the rule you've to set up:
<your RPi local IP address> External port: 51413 Internal port: 51413 Protocol: TCP
Therefore, the only port you should need to open in ufw
is 51413.