RMI ERROR

I wrote my application in java to use rmi server/client, when i compile it compiled successfully but when i run it. its give me the following error

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: CharServer_stub

but i was advice to run using java -j-classpath -j ChatServer
i does ;that, then it give the following error

java.rmi.ConnectException: Connection refused to host: localhost; nested exception is: java.net.ConnectException: Connection refused: connect

here are my complete codes
import java.rmi.*;

public interface ServerRemote extends Remote
{
//remote methods that register a new client
public int registerClient(ClientRemote cr) throws RemoteException;
// remote method that removes the existing client
public void removeClient(int i) throws RemoteException;
// remote interface that display the typed text
public void showText(String str) throws RemoteException;

}
I saved it as ServerRemote.java

import java.net.*;
import java.io.*;
import java.util.*;
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.LocateRegistry;

public class ChatServer implements Remote, ServerRemote
{
private static ChatServer rmi;
//private static ServerRemote server;
private ClientRemote cr;
Vector v = new Vector();


public static void main(String arg[])
{

System.setSecurityManager(new RMISecurityManager());
try
{

// server object
rmi = new ChatServer();
System.out.println("Registry is created. ");
// exporting server object
UnicastRemoteObject.exportObject(((ServerRemote)rmi));

//binding server object
Naming.rebind("//82.128.10.51/ServerRemote", rmi);
System.out.println("Binding Completed");
System.out.println("Server is wating for client request...");
}
catch(java.rmi.UnknownHostException uhe)
{

System.out.println("Error");

}
catch(RemoteException re)
{
System.out.println("Error " + re);
}
catch(MalformedURLException mURLe)
{
System.out.println(" Error " + mURLe);
}
}
//registerClient Method
public int registerClient( ClientRemote cr) throws RemoteException
{
int i=0;
System.out.println("Client is requesting a connection...");
//add a new Client
v.addElement(cr);
// update the index
i = v.indexOf(cr);
System.out.println("Timer is started" + v.size());
return i;

}
//RevoteClient() method
public void removeClient(int i) throws RemoteException
{
//remove the client
v.removeElementAt(i);
}

// showText() method
public void showText(String str) throws RemoteException
{
System.out.println(str);
for(int i =0; i<v.size(); i++ )
{
ClientRemote cr1 = (ClientRemote)v.elementAt(i);
if(cr1 != null)
cr1.getString(str);
}

}
}
i saved it as ChatServer.java

import java.rmi.*;

public interface ClientRemote extends Remote
{
// remote object
public void getString(String str) throws RemoteException;

}
i saved it as ClientRemote.java

import javax.swing.*;
import java.awt.*;
import java.lang.*;
import java.awt.event.*;
import java.rmi.*;
import java.rmi.server.*;
import java.io.*;
import java.sql.*;

public class chat extends JFrame implements ActionListener, KeyListener, ClientRemote
{
JPanel panel, panel2, panel3, panel4, panel5;

JTextArea txtachatmessage, txtaeditor;
//JTextField txtaeditor;
JButton cmdsend;
JLabel lblmessage, lblchat;
ServerRemote ser;
private String mystr;
private static String name ="";
int i =0;
public chat()
{
super("Instant Chat Message");





panel = new JPanel();
panel2 = new JPanel();
panel3 = new JPanel();
panel4 = new JPanel();
panel5 = new JPanel();


lblchat = new JLabel("Instant Send and Received Message");
txtachatmessage = new JTextArea(20, 35);


panel.add(lblchat);
txtachatmessage.setLineWrap(true);
txtachatmessage.setEditable(false);

panel2.add(new JScrollPane(txtachatmessage, 20, 31));
lblmessage = new JLabel("Type your Message here");
txtaeditor = new JTextArea(3,28);
txtaeditor.setLineWrap(true);
txtaeditor.addKeyListener(this);
cmdsend = new JButton("Send");
cmdsend.addActionListener(this);
panel3.add(lblmessage);
panel4.add(new JScrollPane(txtaeditor, 20, 31));
panel4.add(cmdsend);

Box box = Box.createVerticalBox();

box.add(panel);
box.add(panel2);
box.add(panel3);
box.add(panel4);
panel5.add(box);
add(panel5);



setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);
setSize(450,500);
setVisible(true);
setResizable(false);
//setExtendedState(MAXIMIZED_HORIZ);
//setMaximizedBounds();

try
{
//set the security manager
System.setSecurityManager(new RMISecurityManager());
//export the client object
UnicastRemoteObject.exportObject(this);
//find server remote object in the RMI registry
//ser = (ServerRemote)Naming.lookup("//" + getCodeBase().getHost() + "/Server");
//ser = (ServerRemote)Naming.lookup("rmi://localhost/ServerRemote");
ser = (ServerRemote)Naming.lookup("//82.128.10.51/ServerRemote");
}
catch(Exception e)
{
System.out.println("Error:" + e);
}
try
{
//Register the client
i = ser.registerClient(this);
}
catch(Exception e)
{
System.out.println("Error: " + e);
}
}

public void sendme()
{
try
{
ser.showText( name + ":" + txtaeditor.getText());
}
catch(Exception e)
{
System.out.println("Error: " + e);
}

}

public void getString(String str) throws RemoteException
{
txtachatmessage.append(str + "
");
}
public void actionPerformed(ActionEvent e)
{
sendme();
}

public void keyPressed(KeyEvent p)
{
mystr = p.getKeyText(p.getKeyCode());
}

public void keyReleased(KeyEvent r)
{
mystr = r.getKeyText(r.getKeyCode());
}

public void keyTyped(KeyEvent t)
{
if (mystr.equals("Enter"))
sendme();

}

public static void main(String arg[])
{
name = arg[0];
chat ch = new chat();
ch.show();
ch.setTitle(name);

}
}
i saved it as chat.java

pls need help my gurus. thx

Comments

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion