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

📄 server.java

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

public class Server extends PortableRemoteObject implements RMIInterface {
    // must explicitly create default constructor to throw RemoteException
    public Server() throws RemoteException {
    }

    // implementation of RMIInterface methods
    public String hello() throws RemoteException {
	return "Hello there!";
    }

    public SerClass alterClass(SerClass classObject) throws RemoteException {
	// change the values of SerClass and return it.
	classObject.setX( 
	   classObject.getX() + 5 ); // add 5 to X
	classObject.setString( 
	   classObject.getString() + " : I've altered you" ); // alter the string
	return classObject;
    }	

    public static void main(String[] args) {
	try {
 	    Server s = new Server();

	    // create the naming context
            Context initialNamingContext = new InitialContext();
            initialNamingContext.rebind("Server", s );

	    System.out.println("Hello Server waiting...");
	    // it's that easy - we're registered and listening for incoming requests

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

⌨️ 快捷键说明

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