Rithik Tank
Rithik Tank

Reputation: 39

I am attempting to establish a remote server client relationship using CORBA and CosNaming. However, I continue to get the same exception

I'm making use of CosNaming because I do not want to hardcode an IOR on my client side and have been unable to figure out why I continue to get an exception. The code works when i attempt to make a server and client on the same machine, but I encounter exceptions upon attempting remote connections to the server.

This is the server side of my code

package server.controller;

import org.omg.CORBA.ORB;
import org.omg.CosNaming.NameComponent;
import org.omg.CosNaming.NamingContextExt;
import org.omg.CosNaming.NamingContextExtHelper;
import org.omg.CosNaming.NamingContextPackage.CannotProceed;
import org.omg.CosNaming.NamingContextPackage.InvalidName;
import org.omg.CosNaming.NamingContextPackage.NotFound;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAHelper;
import org.omg.PortableServer.POAPackage.ObjectNotActive;
import org.omg.PortableServer.POAPackage.ServantNotActive;
import org.omg.PortableServer.POAPackage.WrongPolicy;
import server.model.BoggleApp.BoggleClient;
import server.model.BoggleApp.BoggleClientHelper;
import server.model.DataPB;
import server.model.ServerImplementation;

public class Server{

    private ORB orb;

    private POA rootpoa;

    private ServerImplementation serverImpl;

    org.omg.CORBA.Object ref;

    BoggleClient href;

    org.omg.CORBA.Object objRef;

    NamingContextExt ncRef;

    String path = "WordFactory";

    NameComponent[] pathname;

    public void run(String[] args) {
        try {
            this.orb = ORB.init(args, null);

            this.rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
            rootpoa.the_POAManager().activate();

            this.serverImpl = new ServerImplementation();

            this.ref = rootpoa.servant_to_reference(this.serverImpl);
            this.href = BoggleClientHelper.narrow(this.ref);

            this.objRef = orb.resolve_initial_references("NameService");

            this.ncRef = NamingContextExtHelper.narrow(objRef);
            this.path = "WordFactory";
            this.pathname = ncRef.to_name(path);

            ncRef.rebind(this.pathname, this.href);

            System.out.println("Server is running...");
            orb.run();

        }catch (Exception e) {
            e.printStackTrace();
        }

    }

    public void stop(){
        try {
            rootpoa.deactivate_object(rootpoa.servant_to_id(serverImpl));
            System.out.println("Server is stopped.");
        } catch (WrongPolicy e) {
            throw new RuntimeException(e);
        } catch (ObjectNotActive e) {
            throw new RuntimeException(e);
        } catch (ServantNotActive e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) {
        Server s = new Server();
        String[] a =  {"-ORBINITIALHOST", "localhost", "-ORBINITIALPORT", "10000"};
        s.run(a);
    }

    public ServerImplementation getServerImpl() {
        return serverImpl;
    }
}

This is the client of my code which attempts to remotely connect to my server found on the same network

package client.model;

import client.controller.LoginController;
//import client.model.BoggleApp.BoggleClient;
import client.model.BoggleApp.BoggleClient;
import client.model.BoggleApp.BoggleClientHelper;
import client.view.LoginView;
import org.omg.CORBA.ORB;
import org.omg.CosNaming.NamingContextExt;
import org.omg.CosNaming.NamingContextExtHelper;


public class Client {

    private static BoggleClient wfImpl;

    public void run (String args[]) {
        try {
            ORB orb = ORB.init(args, null);

            org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");

            NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

            String name = "WordFactory";

            wfImpl = BoggleClientHelper.narrow(ncRef.resolve_str(name));

            System.out.println(wfImpl.getFullName("ramon"));

        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static void main(String[] args) {
        String[] a = {"-ORBINITIALHOST", "192.168.50.160", "-ORBINITIALPORT", "10000"};
        Client c = new Client();
        c.run(a);
    }
}

This is the exception I'm getting

May 06, 2024 3:03:01 PM com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl <init>
WARNING: "IOP00410201: (COMM_FAILURE) Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: 100.118.181.16; port: 59109"
org.omg.CORBA.COMM_FAILURE:   vmcid: SUN  minor code: 201  completed: No
    at com.sun.corba.se.impl.logging.ORBUtilSystemException.connectFailure(ORBUtilSystemException.java:2200)
    at com.sun.corba.se.impl.logging.ORBUtilSystemException.connectFailure(ORBUtilSystemException.java:2221)
    at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.<init>(SocketOrChannelConnectionImpl.java:223)
    at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.<init>(SocketOrChannelConnectionImpl.java:236)
    at com.sun.corba.se.impl.transport.SocketOrChannelContactInfoImpl.createConnection(SocketOrChannelContactInfoImpl.java:119)
    at com.sun.corba.se.impl.protocol.CorbaClientRequestDispatcherImpl.beginRequest(CorbaClientRequestDispatcherImpl.java:187)
    at com.sun.corba.se.impl.protocol.CorbaClientDelegateImpl.request(CorbaClientDelegateImpl.java:137)
    at org.omg.CORBA.portable.ObjectImpl._request(ObjectImpl.java:449)
    at client.model.BoggleApp._BoggleClientStub.getFullName(_BoggleClientStub.java:449)
    at client.model.Client.run(Client.java:29)
    at client.model.Client.main(Client.java:40)
Caused by: java.net.ConnectException: Connection refused
    at sun.nio.ch.Net.connect0(Native Method)
    at sun.nio.ch.Net.connect(Net.java:482)
    at sun.nio.ch.Net.connect(Net.java:474)
    at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:647)
    at java.nio.channels.SocketChannel.open(SocketChannel.java:189)
    at com.sun.corba.se.impl.transport.DefaultSocketFactoryImpl.createSocket(DefaultSocketFactoryImpl.java:95)
    at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.<init>(SocketOrChannelConnectionImpl.java:207)
    ... 8 more

org.omg.CORBA.COMM_FAILURE:   vmcid: SUN  minor code: 201  completed: No
    at com.sun.corba.se.impl.logging.ORBUtilSystemException.connectFailure(ORBUtilSystemException.java:2200)
    at com.sun.corba.se.impl.logging.ORBUtilSystemException.connectFailure(ORBUtilSystemException.java:2221)
    at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.<init>(SocketOrChannelConnectionImpl.java:223)
    at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.<init>(SocketOrChannelConnectionImpl.java:236)
    at com.sun.corba.se.impl.transport.SocketOrChannelContactInfoImpl.createConnection(SocketOrChannelContactInfoImpl.java:119)
    at com.sun.corba.se.impl.protocol.CorbaClientRequestDispatcherImpl.beginRequest(CorbaClientRequestDispatcherImpl.java:187)
    at com.sun.corba.se.impl.protocol.CorbaClientDelegateImpl.request(CorbaClientDelegateImpl.java:137)
    at org.omg.CORBA.portable.ObjectImpl._request(ObjectImpl.java:449)
    at client.model.BoggleApp._BoggleClientStub.getFullName(_BoggleClientStub.java:449)
    at client.model.Client.run(Client.java:29)
    at client.model.Client.main(Client.java:40)
Caused by: java.net.ConnectException: Connection refused
    at sun.nio.ch.Net.connect0(Native Method)
    at sun.nio.ch.Net.connect(Net.java:482)
    at sun.nio.ch.Net.connect(Net.java:474)
    at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:647)
    at java.nio.channels.SocketChannel.open(SocketChannel.java:189)
    at com.sun.corba.se.impl.transport.DefaultSocketFactoryImpl.createSocket(DefaultSocketFactoryImpl.java:95)
    at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.<init>(SocketOrChannelConnectionImpl.java:207)
    ... 8 more

Process finished with exit code 0

Upvotes: 0

Views: 86

Answers (0)

Related Questions