📄 dnsservermain.java
字号:
package dnsServer;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.UnknownHostException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
public class DnsServerMain {
/**
* @param args
*/
public static void main(String[] args) {
ServiceList list=new ServiceList();
DnsServerMain.writeUserListToFile(list);
InetAddress ip;
String url;
try {
ip = InetAddress.getLocalHost();
url = ip.getHostAddress();
System.out.println("目录服务器的地址为:"+url+":1099");
String ServiceURL = "rmi://"+url+":1099/DnsServerService";
try {
// 建立服务对象
DnsServerServiceImpl impl = new DnsServerServiceImpl();
// 启动注册表
LocateRegistry.createRegistry(1099);
// 绑定
Naming.rebind(ServiceURL, impl);
System.out.println("目录服务器正在运行...");
} catch (RemoteException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
}
} catch (UnknownHostException e1) {
e1.printStackTrace();
}
}
public static void writeUserListToFile(ServiceList list){
ObjectOutputStream oos;
FileOutputStream fos = null;
try {
fos = new FileOutputStream("serviceList.txt",false);
oos = new ObjectOutputStream(fos);
oos.writeObject(list);
oos.flush();
oos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -