Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7604251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:51:48+00:00 2026-05-30T23:51:48+00:00

I am creating my first, very simple RMI client-server application. Here is the code:

  • 0

I am creating my first, very simple RMI client-server application.

Here is the code:

Interface “ICommunication”

package itu.exercies.RMI.server;

    import java.rmi.Remote;
    import java.rmi.RemoteException;

public interface ICommunication extends Remote  
{
    public String doCommunicate(String name) throws RemoteException; 

}

Interface implementation “CommunicationImpl”:

package itu.exercies.RMI.server;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public class CommunicationImpl extends UnicastRemoteObject implements ICommunication {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    public CommunicationImpl() throws RemoteException {
        super();

    }

    @Override
    public String doCommunicate(String name) throws RemoteException {

        return "Hello this is server , whats up " +name+ " ?!\n";
    }

}

Here is my main class of the server “CommunicationServer”:

package itu.exercies.RMI.server;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.RemoteException;


public class CommunicationServer {
    /**
     * @param args
     * @throws RemoteException 
     * @throws MalformedURLException 
     */
    public static void main(String[] args) throws RemoteException, MalformedURLException {
        CommunicationImpl imp = new CommunicationImpl();
        Naming.rebind("CommunicationImpl", imp);
        System.out.println("Server started...");
        System.out.println("Object successfully registered. It is bound to the name 'CommunicationImpl'.");

    }

}

And this is my client “CommunicationClient”:

package itu.exercies.RMI.client;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

import itu.exercies.RMI.server.CommunicationImpl;

public class CommunicationClient {
    public static void main(String[] args) throws MalformedURLException, RemoteException, NotBoundException {

        String url = new String("rmi://localhost/CommunicationImpl");
        CommunicationImpl comm = (CommunicationImpl)Naming.lookup(url);
        String reply = comm.doCommunicate("Wiktor");
        System.out.println(reply);


    }

}

Now when I try to run it:

  1. I navigate to bin directory of my project using Terminal
  2. I run rmiregistry from there
  3. I run my CommunicationServer from new Terminal window (and it prints out the messages so it seems to work)
  4. I open third terminal window and when i try to run my CommunicationClient it throws an exception.

java itu.exercies.RMI.client.CommunicationClientException in thread “main” java.lang.ClassCastException: $Proxy0 cannot be cast to itu.exercies.RMI.server.CommunicationImpl
at itu.exercies.RMI.client.CommunicationClient.main(CommunicationClient.java:14)

So far I have tried to fix it by creating a stub of ‘CommunicationImpl’ object using rmic but now instead of ‘$Proxy0’ the error refers to ‘CommunicationImpl_Stub’:

Exception in thread “main” java.lang.ClassCastException: itu.exercies.RMI.server.CommunicationImpl_Stub cannot be cast to itu.exercies.RMI.server.CommunicationImpl
at itu.exercies.RMI.client.CommunicationClient.main(CommunicationClient.java:14)

At this point I have no idea were to look for errors. Can anybody give me any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:51:49+00:00Added an answer on May 30, 2026 at 11:51 pm

    Replace

    CommunicationImpl comm = (CommunicationImpl) Naming.lookup(url);
    

    with

    ICommunication comm = (ICommunication) Naming.lookup(url);
    

    CommunicationImpl is the server implementation of the ICommunication. The client neither knows nor cares about the implementation, only the interface.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a very simple EF4 code first project with one entity. public
I am creating a very simple forum as my first MVC project. My database
I am creating a very simple quiz application with jQuery. How it works is
I just finished creating my first major application in C#/Silverlight. In the end the
I often refactor code first by creating an inner class inside the class I'm
I'm creating a very simple phone directory for a homework assignment but I'm stuck.
Let's say there is a simple test code typedef struct { int first; int
I have a very simple C++ application. #include <stdio.h> #include <iostream> int main(int argc,
I'm very new to C++ and I am creating my first class. I have
This is my first Java application I am creating (using Eclipse IDE) and the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.