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 6897289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:09:01+00:00 2026-05-27T07:09:01+00:00

I am currently working on an assignment that deals with RMI. Essentially, it is

  • 0

I am currently working on an assignment that deals with RMI. Essentially, it is just a chatroom. The problem that I am running into, though, is that I want to be able to get a username variable from my client, but that variable is not part of its remote interface:

public interface MulticastClient extends Remote {

    public void deliver( MulticastClient sender, String channel, 
        Serializable message) throws RemoteException;
}

From what I understand, since sender is really a remote object, I can only access the methods and variables defined in the interface. Since this is a homework assignment I cannot change the interface (it was given to us).

Some code from my MulticastClient implementation:

public class ChatClient implements MulticastClient {

       ...
       private String username;

    @Override
    public void deliver(MulticastClient sender, String channel,
        Serializable message) throws RemoteException {

    String senderName = ((ChatClient)sender).getUsername();
    System.out.println("\r" + senderName + ": " + message.toString());
    }

    public String getUsername() {
        return username;
    }

    ...

    public static void main(String[] args) throws Exception{
            ...

    ChatClient client = new ChatClient();
    MulticastClient stub = (MulticastClient)UnicastRemoteObject.exportObject(client, 0);

    Registry reg = LocateRegistry.getRegistry(hostname, port);
    MulticastService server = (MulticastService)reg.lookup(SERVER_NAME);

            ...
    }
}

When I attempt to user the deliver method, as it is now, the error I get is:

Exception in thread "Thread-2" java.lang.ClassCastException: $Proxy0 cannot
be cast to csci4401.mc.ChatClient

I know that the cast in deliver() is causing the problem, but I am not sure what the correct way to do this is. Is there another way that I can get the ChatClient’s username?

  • 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-27T07:09:01+00:00Added an answer on May 27, 2026 at 7:09 am

    What you can access remotely is defined by the remote interface, by definition. What you have at the client isn’t the remote object itself, it is a proxy for it that implements the same remote interface. Hence your exception.

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

Sidebar

Related Questions

I'm currently working through an assignment that deals with Big-O and running times. I
Currently working with converting SQLException error messages into messages that are more useful for
The goal of the assignment that I'm currently working on for my Data Structures
I'm currently working on a program (for fun, this is not an assignment) that
Currently I'm working on an assignment that requires that I create a program in
I am currently in an introductory c++ class and am working assignment that sorts
I'm currently working on an assignment that has me creating a Map class in
Currently I'm working on an assignment and using C++ for the first time. I'm
Im currently working on a game that uses multi touch to apply zoom to
Am currently working on an application that requires users to submit posts and comments

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.