Getting NotBoundException while writing a Java RMI chat application :-/

user2855719

I have written a Java RMI chat application. There are four classes and two interfaces. Here they are:

ChatClient

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.Scanner;
com.za.tutorial.rmi.server.ChatServerIF;

public class ChatClient extends UnicastRemoteObject implements ChatClientIF,Runnable {
private ChatServerIF chatServer;
private String name = null;

protected ChatClient(String name, ChatServerIF chatServer) throws RemoteException {
    this.name = name;
    this.chatServer = chatServer;
    chatServer.registerChatClient(this);
}

public void retrieveMessage(String message) throws RemoteException {
    // TODO Auto-generated method stub
    System.out.println(message);
}

public void run() {
    Scanner scanner = new Scanner(System.in);
    String message;
    while(true){
        message = scanner.nextLine();
        try {
            chatServer.broadcastMessage(name + " : " + message);
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    }

}

ChatClientDriver

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import com.za.tutorial.rmi.server.ChatServerIF;

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

String chatServerURL = "rmi://localhost/RMIChatServer";
ChatServerIF chatServer = (ChatServerIF) Naming.lookup(chatServerURL);
new Thread(new ChatClient(args[0],chatServer)).start();
}
}

ChatClientInterface

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

public interface ChatClientIF extends Remote {
void retrieveMessage(String message) throws RemoteException;
}

ChatServer

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import com.za.tutorial.rmi.client.ChatClientIF;

public class ChatServer extends UnicastRemoteObject implements ChatServerIF {


private ArrayList<ChatClientIF> chatClients;
protected ChatServer() throws RemoteException {
    chatClients = new ArrayList<ChatClientIF>();
    }

public synchronized void registerChatClient(ChatClientIF chatClient)
        throws RemoteException {
    this.chatClients.add(chatClient);
}

public synchronized void broadcastMessage(String message) throws RemoteException {
    int i = 0;
    while(i < chatClients.size()){
        chatClients.get(i++).retrieveMessage(message);
    }
}
}

ChatServerDriver

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

public class ChatServerDriver {

public static void main(String[] args) throws RemoteException, MalformedURLException {
Naming.rebind("RMIChatServer", new ChatServer());
}
}

ChatServerInterface

import java.rmi.Remote;
import java.rmi.RemoteException;
import com.za.tutorial.rmi.client.ChatClientIF;

public interface ChatServerIF extends Remote {
void registerChatClient(ChatClientIF chatClient) throws RemoteException;
void broadcastMessage(String message) throws RemoteException;
}

When I run it on Commando, first of all I run rmic ChatClient and ChatServer, then rmiregistry. Then i run chatServerDriver which works completely fine. after that, when I run chatClientDriver with a name, I get the following error, I dont understand why :/ Can I get any solution for this?

Thanks :)

Exception in thread "main" java.rmi.NotBoundException: RMIChatServer
    at sun.rmi.registry.RegistryImpl.lookup(RegistryImpl.java:136)
    at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
    at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:409)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267)
    at sun.rmi.transport.Transport$1.run(Transport.java:177)
    at sun.rmi.transport.Transport$1.run(Transport.java:174)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
    at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
    at sun.rmi.server.UnicastRef.invoke(Unknown Source)
    at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
    at java.rmi.Naming.lookup(Unknown Source)
    at com.za.tutorial.rmi.client.ChatClientDriver.main(ChatClientDriver.java:15)
pjp

It also looks like you have a different address in Rebind to what is being used by the client to connect.

Naming.rebind("//localhost/RMIChatServer", new ChatServer());

There's an example implementation on the following Wikipedia page which may be worth comparing against your code. http://en.wikipedia.org/wiki/Java_remote_method_invocation

Note that using Java 1.5+ you don't need to use rmic anymore see Do we really need to create Stub in java RMI?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Exception in thread "main" java.rmi.NotBoundException

From Dev

Exception in thread "main" java.rmi.NotBoundException

From Dev

Writing a secure RMI server-client application

From Dev

I am getting different errors on a java Chat application using socket

From Dev

Terminate Java RMI server application

From Dev

RMI Java application not working as expected

From Dev

java.io.File getting extra char while writing into file

From Dev

Java RMI: running RMI application over the Internet with public IP of router

From Dev

Java RMI freezes while calling a function on a stub

From Dev

RMI chat over Internet

From Dev

Java RMI application doesn't quit

From Dev

Is there a way to completely disable RMI in a java application?

From Dev

Running Java RMI application on two machines - ConnectException

From Dev

Is there a way to completely disable RMI in a java application?

From Dev

Client Server chat application in java

From Dev

Multi client chat application In java

From Dev

Client Server chat application in java

From Dev

Getting error in converting Json response to java object while writing test cases

From Dev

Getting different output while writing to file

From Dev

Getting this error while trying to connect facebook chat using smack

From Dev

getting an issue while archiving opentok audio/video chat

From Dev

Java chat application using Swing (Conceptual)

From Dev

Multithreaded client server chat application in java

From Dev

java chat application not working on other machines

From Dev

Client Server Chat Application in Java without broadcasting

From Dev

RMI object not getting refreshed

From Dev

Getting ssl handshake error while communicating with paypal server in my java application

From Dev

Getting too many file descriptor open, in java application while performing file operation

From Dev

Getting ssl handshake error while communicating with paypal server in my java application

Related Related

  1. 1

    Exception in thread "main" java.rmi.NotBoundException

  2. 2

    Exception in thread "main" java.rmi.NotBoundException

  3. 3

    Writing a secure RMI server-client application

  4. 4

    I am getting different errors on a java Chat application using socket

  5. 5

    Terminate Java RMI server application

  6. 6

    RMI Java application not working as expected

  7. 7

    java.io.File getting extra char while writing into file

  8. 8

    Java RMI: running RMI application over the Internet with public IP of router

  9. 9

    Java RMI freezes while calling a function on a stub

  10. 10

    RMI chat over Internet

  11. 11

    Java RMI application doesn't quit

  12. 12

    Is there a way to completely disable RMI in a java application?

  13. 13

    Running Java RMI application on two machines - ConnectException

  14. 14

    Is there a way to completely disable RMI in a java application?

  15. 15

    Client Server chat application in java

  16. 16

    Multi client chat application In java

  17. 17

    Client Server chat application in java

  18. 18

    Getting error in converting Json response to java object while writing test cases

  19. 19

    Getting different output while writing to file

  20. 20

    Getting this error while trying to connect facebook chat using smack

  21. 21

    getting an issue while archiving opentok audio/video chat

  22. 22

    Java chat application using Swing (Conceptual)

  23. 23

    Multithreaded client server chat application in java

  24. 24

    java chat application not working on other machines

  25. 25

    Client Server Chat Application in Java without broadcasting

  26. 26

    RMI object not getting refreshed

  27. 27

    Getting ssl handshake error while communicating with paypal server in my java application

  28. 28

    Getting too many file descriptor open, in java application while performing file operation

  29. 29

    Getting ssl handshake error while communicating with paypal server in my java application

HotTag

Archive