rmiserver.java

来自「test upload file 1111111」· Java 代码 · 共 87 行

JAVA
87
字号
package com.vest.kungfu.utility;

import java.net.InetAddress;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Date;

public class RmiServer extends java.rmi.server.UnicastRemoteObject implements
		InterfaceCrc

{
	int thisPort;

	String thisAddress;

	Registry registry; // rmi registry for lookup the remote objects.

	public String crc(String code) throws RemoteException {
		// TODO Auto-generated method stub
		Pwdcrc crc=new Pwdcrc(); 
		return crc.CRCPassword(code);
	}

	public RmiServer() throws RemoteException

	{

		try {

			// get the address of this host.

			thisAddress = (InetAddress.getLocalHost()).toString();

		}

		catch (Exception e) {

			throw new RemoteException("can't get inet address.");

		}

		thisPort = 3232; // this port(registry’s port)

		System.out.println("-->Local:" + thisAddress + ",port=" + thisPort);

		try {

			// create the registry and bind the name and object.

			registry = LocateRegistry.createRegistry(thisPort);

			registry.rebind("RMICRC", this);
			System.out.println("-->RMI服務器啟動了!等待客戶端的連接 @"+(new Date())); 

		}

		catch (RemoteException e) {

			throw e;

		}

	}

	static public void main(String args[])

	{

		try {

			RmiServer s = new RmiServer();

		}

		catch (Exception e) {

			e.printStackTrace();

			System.exit(1);

		}

	}

}

⌨️ 快捷键说明

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