正在加载图片...
Writing an RMI Server Overview import iava.rmi.*: import java.rmi.server.*; erver extends UnicastRemoteobject public static void main String [args throws RemoteException,java.net.MalformedURLException, RMISecurityException //1.Set Security Manager /2.Create an object instance //3.Register object into the name space In addition to implementing the interface,we also need to write the server's main program.RMI currently does not support server programs as applets,so the main program needs to be a standalone Java application.You can either code a separate Java class for main,or you can just code a main method in the implementation class as we did here. Note also that we coded the main function to throw any RMI-related exceptions to the command line.That's OK for a small sample program like this,but in a real program you will probably instead bracket the steps that follow in separate try-catch blocks so you can perform better error handling. The steps that the server main typically does are: 1.Install a security manager class that lets the server program accept stub classes from other machines 2.Create an instance of the server object 3.Register the server object into the RMI naming registry so that client programs can find it Let's now take a closer look at each of these steps.Writing an RMI Server Overview import java.rmi.*; import java.rmi.server.*; public class MeetingServer extends UnicastRemoteObject implements Meeting { . . . public static void main ( String [] args ) throws RemoteException, java.net.MalformedURLException, RMISecurityException { // 1. Set Security Manager // 2. Create an object instance // 3. Register object into the name space } } In addition to implementing the interface, we also need to write the server's main program. RMI currently does not support server programs as applets, so the main program needs to be a standalone Java application. You can either code a separate Java class for main, or you can just code a main method in the implementation class as we did here. Note also that we coded the main function to throw any RMI-related exceptions to the command line. That's OK for a small sample program like this, but in a real program you will probably instead bracket the steps that follow in separate try-catch blocks so you can perform better error handling. The steps that the server main typically does are: 1. Install a security manager class that lets the server program accept stub classes from other machines 2. Create an instance of the server object 3. Register the server object into the RMI naming registry so that client programs can find it Let's now take a closer look at each of these steps
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有