Java API——RMIIO入門教程(3)遠端流傳輸示例之RMIIO伺服器端原始碼

鍾超發表於2011-12-01

RMI Server端。這個其實跟RMIIO關係不大。


package com.sinosuperman.rmiio2;

import java.net.MalformedURLException;
import java.rmi.AlreadyBoundException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;


public class RmiioServer2 {
	
	public static void main(String[] args) {
		
		try {
			/* Create a Remote object. */
			RmiioService2 testRMIIO = new RmiioServiceImpl2();
			
			/* Create a registry object with 1235 port. */
			LocateRegistry.createRegistry(2234);
			
			/* Register the Remote object to RMI registry server, and name it as testrmi. */
			Naming.bind("rmi://localhost:2234/testrmiio", testRMIIO);
			
			System.out.println("註冊遠端物件成功");
			
		} catch (RemoteException e) {
			System.out.println("遠端物件建立異常");
			e.printStackTrace();
		} catch (MalformedURLException e) {
			System.out.println("URL畸形異常");
			e.printStackTrace();
		} catch (AlreadyBoundException e) {
			System.out.println("重複繫結異常");
			e.printStackTrace();
		}
	}
}


相關文章