server.java

来自「网络聊天」· Java 代码 · 共 56 行

JAVA
56
字号
package server;

import java.rmi.*;
import java.rmi.server.*;
import java.net.*;
import java.util.*;

public class Server extends UnicastRemoteObject implements RemoteInterface {
	String text;
	Vector clientList = null;
	
	public Server() throws RemoteException{
		super();
		clientList = new Vector();
	}
	
	public String getChatText() throws RemoteException{
		return text;
		
	}
	
	public void setChatText(String b) throws RemoteException{
		
		text = b;
		for (Enumeration clients = clientList.elements();
		     clients.hasMoreElements();){
			Notifiable thingToNotify = (Notifiable) clients.nextElement();
			thingToNotify.notify(new Integer(0));
			
		}
	}
	
	public void registerForNotification(Notifiable n) throws RemoteException{
		
		clientList.addElement(n);
		
	}
	
	public static void main(String[] args) {
		
		System.setSecurityManager(new RMISecurityManager());
		
		try{
			
			Server thisOne = new Server();
			Naming.rebind("rmi://211.87.226.1/test", thisOne);
			
		}
		catch(Exception e){
			e.printStackTrace();
		}
	
	}

}

⌨️ 快捷键说明

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