rmichatserverimpl.java

来自「简单的RMI应用 对初学者了解rmi有很大的帮助」· Java 代码 · 共 49 行

JAVA
49
字号
import java.rmi.server.*;import java.rmi.*;import java.util.*;public class RMIChatServerImpl extends UnicastRemoteObject 	implements RMIChatServer {			Vector  clientList;	public RMIChatServerImpl() throws RemoteException {		super();		clientList = new Vector();	}	public synchronized void register(RMIChatClient client, 		String name) throws RemoteException {					clientList.addElement(client);		broadcast(name + "丛捞 涝厘窍继嚼聪促.");	}	public void broadcast(String msg) throws RemoteException {		synchronized(clientList) {			Enumeration e = clientList.elements();			while(e.hasMoreElements()) {				RMIChatClient c = (RMIChatClient) e.nextElement();				c.setMessage(msg);			}		}	}	public synchronized void unregister(RMIChatClient client, 		String name) throws RemoteException {					clientList.removeElement(client);		broadcast(name + "丛捞 硼厘窍继嚼聪促.");	}	public static void main(String args[]) {		try {			RMIChatServerImpl c = new RMIChatServerImpl();			Naming.rebind("rmi://localhost/chat", c);			System.out.println("RMI Chat Server is ready.");		} catch(Exception ex) {			System.out.println(ex);		}	}}

⌨️ 快捷键说明

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