简体   繁体   English

套接字编程中的端口转发

[英]Port Forwarding in socket Programming

I created a program in Java using socket programming, which sends messages between two devices.我在 Java 中使用套接字编程创建了一个程序,它在两个设备之间发送消息。 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.我有一个疑问,我们在计算机中使用了许多连接到 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?那么为什么这个 java 程序需要端口转发之类的东西才能工作呢?

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.原因是 sockets 默认为本地主机,当服务器托管在本地网络上时,您无法通过简单地将服务器的 ip 放入客户端来使用它,将服务器放到互联网上,我们使用端口转发。 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... 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问题...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM