📄 server.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -