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

📄 client.java

📁 这里面有150个从简单到难的java 程序的源代码
💻 JAVA
字号:
/*
 * Client application
 */
import javax.rmi.PortableRemoteObject;
import javax.naming.Context;
import javax.naming.InitialContext;

public class Client {
    public static void main(String[] args) {
	try {
	    // get the naming context
            Context ic = new InitialContext();

	    // get a reference to the remote object
            Object objRef = ic.lookup("Server");

	    // narrow it into our RMIInterface
	    RMIInterface ri = 
		(RMIInterface)PortableRemoteObject.narrow(objRef, RMIInterface.class);
	
	    // call the hello method
	    System.out.println("Recieved from server: "+ri.hello()+"\n");  

	    // now lets try RMI serialization
	    SerClass se = new SerClass(5, "Client string! ");
	    // pass the class to be altered on the server
	    // of course behind the scenes this class is being serialized over IIOP
	    se = ri.alterClass(se);
	    // now let's see the result
	    System.out.println("Serialization results :\n"+
			"Integer was 5 now is "+se.getX()+"\n"+
			"String was \"Client String! \" now is \""+se.getString()+"\"");

	} catch (Exception e) {
	    e.printStackTrace();
	}
    }
}

⌨️ 快捷键说明

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