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

  • Home
  • SEARCH
  • 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 9101737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:12:27+00:00 2026-06-17T01:12:27+00:00

This is my first time that I am using RMI, basically I manage to

  • 0

This is my first time that I am using RMI, basically I manage to run the following RMI example locally on my PC but not via two separate Linux machines.

The server interface:

public interface PowerService extends Remote{
public BigInteger square ( int number )
    throws RemoteException;

public BigInteger power  ( int num1, int num2) 
    throws RemoteException;
}

The server:

public class PowerServiceServer extends UnicastRemoteObject implements
    PowerService {

public PowerServiceServer() throws RemoteException {
    super();
}

public BigInteger square(int number) throws RemoteException {
    imp .....
    return (bi);
}

public BigInteger power(int num1, int num2) throws RemoteException {
    imp .....
    return bi;
}

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

    PowerServiceServer svr = new PowerServiceServer();
    // ... and bind it with the RMI Registry
    Naming.bind("PowerService", svr);
    System.out.println("Service bound....");
}
}

The client:

public class PowerServiceClient {
public static void main(String args[]) throws Exception {
    // Call registry for PowerService
    PowerService service = (PowerService) Naming.lookup("rmi://" + args[0]
            + "/PowerService");
    DataInputStream din = new DataInputStream(System.in);
    for (;;) {
        System.out.println("1 - Calculate square");
        System.out.println("2 - Calculate power");
        System.out.println("3 - Exit");
        System.out.println();
        System.out.print("Choice : ");

        String line = din.readLine();
        Integer choice = new Integer(line);

        int value = choice.intValue();

        switch (value) {
        case 1:
            // Call remote method
            ....................
            break;
        case 2:
            // Call remote method
            ....................
            break;
        case 3:
            System.exit(0);
        default:
            System.out.println("Invalid option");
            break;
        }
    }
}

and the client interfaces is the same like the server

This is what I did in order to run the rmi example:

1) On the server side I created the stub

2) Run rmiregisrty

3) Run the server

4) I copy the stub from the server side to the client side in to the same package

5) Run the client

After running the client I got the following error message:

Exception in thread “main” java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
java.net.ConnectException: Connection refused
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:601)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:110)
at compute.PowerServiceServer_Stub.square(Unknown Source)

is possible that due to some firewall I can’t connect or perhaps I am doing something wrong ??

Thanks

  • 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-06-17T01:12:28+00:00Added an answer on June 17, 2026 at 1:12 am

    This is the problem addressed by java.rmi.server.hostname. See item A.1 in the RMI FAQ. You need to either fix the /etc/hosts misconfiguration that causes it, or set the system property java.rmi.server.hostname in the server JVM to the correct IP address of the server, before exporting any remote objects.

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

Sidebar

Related Questions

This is the first time that this error has come up. I am using
This is my first time that I am using Google API. I am having
This is the first time that I write a TestMethod. Am I using Unit
I'm using *{margin:0; padding:0;} and this is the first time that it breaks me
This is my first time that I use WCF and Android. So, sorry for
I have a database that is currently sharded. This is the first time that
This is the first time I have attempted to create a .dll, that will
That's my first time posting on stackoverflow. I've been finding usefull answers on this
This is my first time using XML documents. What I'm trying to do is
This is my first time using this site and I am quite new to

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.