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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:21:47+00:00 2026-05-27T20:21:47+00:00

This is a question related to RMI. i have 4 .class files an interface,it’s

  • 0

This is a question related to RMI. i have 4 .class files an interface,it’s implementation,a class named server and a class named client.

After starting the rmiregistry i start the server which is like :

import java.rmi.Naming;


public class Server {
  public static void main(String args[]) {
      try {
          to_Server_Impl toServer = new to_Server_Impl();
          Naming.rebind("Server", toServer);
      } catch(Exception exc) {
          System.out.println(exc);
        }
  }
}

Then i start the client whose code is :

import java.rmi.Naming;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;


 public class Client {
   public static void main(String args[]) {
       try {
            to_Server_Intf s_Intf = (to_Server_Intf)Naming.lookup("rmi://127.0.0.1/Server");
          do {  
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String message_to_send = null;
            System.out.println("===Enter your message===");
            message_to_send = br.readLine();
            // sending a message to the server
            String reply = s_Intf.send(message_to_send);
            System.out.println(reply);
          }while(true);
       }catch(Exception exc) {
           System.out.println(exc);
       }
   }
}

Using the reference of the remote object i call the function send of that class, whose code is like:

import java.rmi.*;
import java.rmi.server.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class to_Server_Impl extends UnicastRemoteObject implements to_Server_Intf{
    public to_Server_Impl() throws Exception{ }

@Override
public String send(String str){ // this function receives the message from the Client.
    // this method indirectly replies,by calling reply and then returning the replies string
    String receivedString = str;        
    System.out.println(receivedString);
    System.out.println();
    String reply = reply();

    return reply;
}

@Override
public String reply() { // this function replies the Client
    String replyString = null;
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            replyString = br.readLine();
        }catch(Exception exc) {
            System.out.println(exc);
        }
    return replyString;
 }
}

When i have called the method of the above class the print statements of the above class ,print the messages on the “server” window. How is that possible ?

Client Window:(client is sending the message)

enter image description here

Server Window :(the message gets printed on the server window(the call was directed to the function of class to_Server_Impl). HOW ?)

enter image description here

  • 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-27T20:21:48+00:00Added an answer on May 27, 2026 at 8:21 pm

    I don’t understand your question. In the send method (which is on the server, i.e. it is called by the client remotely on the server), you are printing the received message. Hence, it appears in the server console.

    Edit: Essentially this is how RMI works:

    The server application publishes an interface with the available methods to be called. In your case this is to_Server_Intf. The server also has an implementation of the interface, which is to_Server_Impl. The server publishes the remote object by Naming.bind (or Naming.rebind) to a registry.

    The clients only know about the interface that is also on the server, but not about the implementation. They can do a lookup on the registry and find the remote object by name with Naming.lookup. Now the client has a remote object instance and can call methods on it. This object (s_intf in your client code) is actually a local proxy for the interface implementation present on the server. When the client calls a method on this proxy, the call is actually sent to the object on the server, which is why you are seeing the string in the server console.

    What actually happens when the client calls the method on the local stub is that the parameters (if any) are serialized and a TCP socket message (or whatever the underlying implementation is) is created, which is sent to the server who is listening for incoming requests. On the server side, the message is received, the parameters are deserialized and the correct method is identified from the message and called. After the method returns, again, the result is serialized, a TCP message is created which is sent back to the client.

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

Sidebar

Related Questions

This question is related to this my question . Now I have form in
This question is related to this question I have a field which is a
This question is related to this one . I have two constructors: - (id)initWithBanner:(NSMutableArray
This question is related to that one. But somewhat extended. Let's assume we have
this question is related to routing-filter. I have this in my view: <% form_for
this question is partially related to my last question . I have a generic
This question is related to two different questions I have asked previously: 1) Reproduce
This question is related to extending class methods in Ruby, perhaps more specifically in
This question is related to this one . I have two Android projects inside
This question is related to (but perhaps not quite the same as): Does Django

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.