⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 showtimeclient.java

📁 模拟实现分布式RMI调用时间显示,在两台电脑上实现,运用分布式RMI调用和回调,在Windows命令行下操作.
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -