问题
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