how to connect sockets using static ip java

别说谁变了你拦得住时间么 提交于 2021-02-10 11:58:53

问题


I want to know if I can Connect Java sockets using a static IP Address. I've recently bought static IP from my ISP and I want to connect a Client Program that use Java socket with my laptop (as a server). I've tried it before in a closed network and it work normally, but when I've tried it with distributed network it doesn't work. Here is a piece of my code


Server :

ServerSocket serverSocket = new ServerSocket(5432);    
Socket client = serverSocket.accept();

Client :

Socket socket = new Socket(IP,5432);

The problem is what should the IP be ? The Static IP or the IPV4 ?


回答1:


Assuming the static IP you bought is publicly routable (i.e. not 10.x.x.x, 172.16.x.x-172.31.x.x or 192.168.x.x) and that your routers / firewalls allow access to this IP from the public Internet, you should be able to access that IP from anywhere.



来源:https://stackoverflow.com/questions/32487467/how-to-connect-sockets-using-static-ip-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!