ServerChat.java
上传用户:annion2008
上传日期:2021-03-11
资源大小:38k
文件大小:1k
源码类别:

中间件编程

开发平台:

Java

  1. import chat.servidor.*;
  2. import org.omg.CosNaming.*;
  3. import org.omg.CosNaming.NamingContextPackage.*;
  4. import org.omg.CORBA.*;
  5. import org.omg.PortableServer.*;
  6. import org.omg.PortableServer.POA;
  7. import java.util.Properties;
  8. public class ServerChat
  9. {
  10.     public static void main(String[] args) {
  11.         try {
  12.             /* configures and initializes ORB */
  13.             Properties props = new Properties();
  14.             props.put("org.omg.CORBA.ORBInitialPort", "6666");
  15.             ORB orb = ORB.init(args, props);
  16.             POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
  17.             rootpoa.the_POAManager().activate();
  18.             ServerChatServant serverChat = new ServerChatServant();
  19.             org.omg.CORBA.Object ref = rootpoa.servant_to_reference(serverChat);
  20.             ChatService chatService = ChatServiceHelper.narrow(ref);
  21.             org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
  22.          
  23.             NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
  24.    
  25.            String name = "ChatService";
  26.            NameComponent path[] = ncRef.to_name(name);
  27.            ncRef.rebind(path, ref);
  28.            System.out.println("ChatService early and waiting...");
  29.   
  30.            orb.run();
  31.         } catch (Exception e) {
  32.             System.err.println("Error: " + e.getMessage());
  33.             e.printStackTrace();
  34.         } //catch
  35.     } //main
  36. } //class ServerChat