Port Forwarding in socket Programming

852 Views Asked by At

I created a program in Java using socket programming, which sends messages between two devices. It works great in LAN, but It doesn't work in WAN. I searched a lot and many said to enable port forwarding in my router. I have a doubt, that we use many applications in our computer which connect to the Internet. Various applications also communicate to the server, and none of them require any Port Forwarding . So why this java program requires something like port forwarding to work?

1

There are 1 best solutions below

2
On

I also came across the same question. The reason is that sockets are default to local host and there is no way you can use that by simply putting the ip of the server into the client when the server is hosted on a local network, to put the server onto the internet we use port forwarding . Port forwarding allows to make a static ip for our computer and allows other computer to easily connect to the server and use it , other wise the ip will dynamically change because with out port forwarding the ip will be dynamic not static.. Hope this solves your problem...