如何使用静态IP Java连接套接字 [英] how to connect sockets using static ip java

查看:60
本文介绍了如何使用静态IP Java连接套接字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以使用静态IP地址连接Java套接字.我最近从ISP购买了静态IP,我想将使用Java套接字的客户端程序连接到笔记本电脑(作为服务器).我以前在封闭的网络中尝试过它,但是它可以正常工作,但是当我在分布式网络中尝试过时,它不起作用.这是我的一部分代码

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

服务器:

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

客户:

Socket socket = new Socket(IP,5432);

问题是IP应该是什么? 静态IP还是IPV4?

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

推荐答案

假设您购买的静态IP是可公开路由的(即不是10.xxx,172.16.xx-172.31.xx或192.168.xx),并且您的路由器/防火墙允许从公共Internet访问此IP,您应该可以从任何地方访问该IP.

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.

这篇关于如何使用静态IP Java连接套接字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆