showtimeclient.java

来自「模拟实现分布式RMI调用时间显示,在两台电脑上实现,运用分布式RMI调用和回调,」· Java 代码 · 共 40 行

JAVA
40
字号
import java.rmi.*;
import java.rmi.server.*;

public class ShowTimeClient extends UnicastRemoteObject implements CallBackInterface {
	int interval;
	String time;
	
	public ShowTimeClient(int n) throws RemoteException {
		interval = n;
		time = null;
	}

	public void updateTime(String str) throws RemoteException {
		time = str;
		System.out.println(time);
	}
	
	public int getInterval() throws RemoteException {
		return interval;
	}
	
	public static void main(String[] args) {
		int timeint = 5;
		String address = "localhost";
		if (args.length > 1) {
			timeint = Integer.parseInt(args[0]);
			address = args[1];
		}
		
		ShowTimeInterface remoteobjref = null;
		try {
			remoteobjref = (ShowTimeInterface) Naming.lookup("rmi://" + address + "/remoteobject");
			System.out.println("Found Server.");
			ShowTimeClient client = new ShowTimeClient(timeint);
			remoteobjref.register(client);
		} catch (Exception e) {
			System.out.println("Client exception " + e.getMessage());
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?