如果我指定了错误的端口号,为什么 LocateRegistry.getRegistry() 不会失败?
Why doesn't LocateRegistry.getRegistry() fail if I specify the wrong port number?
我正在尝试分发我实现的一个简单的房间预订系统,我尝试进行研究,这就是我想出的..但是当我 运行 他们并输入不同的端口号时,客户端仍然运行s..如果端口号与我为服务器输入的端口号匹配,难道不应该只 运行 吗?我做错了什么?
对于客户:
public static void main (String[] args)
{
Scanner s = new Scanner (System.in);
int portNum = 1099;//default port
try {
System.out.print("Enter the port number");
portNum= s.nextInt();
Registry reg= LocateRegistry.getRegistry("localhost", portNum);
System.out.println("Connected to RMI server");
对于服务器:
public static void main(String argv[]) {
int portNum = 1099;
try {
Scanner s = new Scanner (System.in);
HotelServer server = new HotelServer ();
//register it with the local naming registry
try
{
System.out.print("Enter The Port Number");
portNum= s.nextInt();
Registry reg= LocateRegistry.createRegistry(portNum);
reg.bind("localhost", server);
System.out.println("Server started");
仅从 LocateRegistry.getRegistry()
获得结果并不表示您已连接到任何东西。它不执行任何网络操作。它只是构造一个存根。如果端口号不正确,只有尝试使用才会发现。
我正在尝试分发我实现的一个简单的房间预订系统,我尝试进行研究,这就是我想出的..但是当我 运行 他们并输入不同的端口号时,客户端仍然运行s..如果端口号与我为服务器输入的端口号匹配,难道不应该只 运行 吗?我做错了什么?
对于客户:
public static void main (String[] args)
{
Scanner s = new Scanner (System.in);
int portNum = 1099;//default port
try {
System.out.print("Enter the port number");
portNum= s.nextInt();
Registry reg= LocateRegistry.getRegistry("localhost", portNum);
System.out.println("Connected to RMI server");
对于服务器:
public static void main(String argv[]) {
int portNum = 1099;
try {
Scanner s = new Scanner (System.in);
HotelServer server = new HotelServer ();
//register it with the local naming registry
try
{
System.out.print("Enter The Port Number");
portNum= s.nextInt();
Registry reg= LocateRegistry.createRegistry(portNum);
reg.bind("localhost", server);
System.out.println("Server started");
仅从 LocateRegistry.getRegistry()
获得结果并不表示您已连接到任何东西。它不执行任何网络操作。它只是构造一个存根。如果端口号不正确,只有尝试使用才会发现。