Bu uygulamamı iki bilgisayar üzerinde çalışacak şekilde yaptım.Birinci bilgisayarda hem MsnServer hem MsnClient sınıfları çalıştırılacak ikinci bilgisayarda ise sadece MsnClient sınıfı çalıştıracaktır.Birinci bilgisayarda olması gereken sınıflar MsnServer, MsnClient,MsnImpl sınıfları ve Msn interfacei ikinci bilgisayarda ise MsnClient sınıfı ve Msn interfacedir.
Msn interface

import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.Vector;

public interface Msn extends Remote
{
public void mesajKaydet(String ad, String str) throws RemoteException;
public Vector mesajAl() throws RemoteException;
}

MsnImpl sınıfı
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.Vector;

public class MsnImpl extends UnicastRemoteObject implements Msn {

private static final long serialVersionUID = 1L;
Vector x=new Vector();
protected MsnImpl() throws RemoteException {
super();
}

public void mesajKaydet(String ad, String msg)
{
x.addElement(ad + " : "+msg);
}
public Vector mesajAl()
{
return x;
}
}

MsnClient sınıfı

import javax.swing.SwingUtilities;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Rectangle;
import java.rmi.Naming;
import java.rmi.RemoteException;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JList;

public class MsnClient extends JFrame implements Runnable {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JTextField txt01 = null;
private JLabel lbl01 = null;
private JLabel lbl02 = null;
private JButton btn = null;
private JList list = null;
private Msn msn;

private JTextField getTxt01()
{
if (txt01 == null)
{
txt01 = new JTextField();
txt01.setBounds(new Rectangle(205, 253, 353, 91));
txt01.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
String ad="EMRAH";
String str=txt01.getText();
try {
msn.mesajKaydet(ad,str);
} catch (RemoteException re) {
System.err.println("RMI mesaj kaydetme hatası: " + re.getMessage());
}
txt01.setText("");
}
});
}
return txt01;
}

private JButton getBtn() {
if (btn == null) {
btn = new JButton();
btn.setBounds(new Rectangle(565, 254, 82, 89));
btn.setText("Gönder");
btn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
String ad="EMRAH";
String str=txt01.getText();
try {
msn.mesajKaydet(ad,str);
} catch (RemoteException re) {
System.err.println("RMI mesaj kaydetme hatası: " + re.getMessage());
}
txt01.setText("");
}
});
}
return btn;
}

private JList getList() {
if (list == null) {
list = new JList();

; list.setBounds(new Rectangle(204, 12, 441, 215));
}
return list;
}

public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
MsnClient thisClass = new MsnClient();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
});
}

public MsnClient() {
super();
initialize();
try {
msn = (Msn) Naming.lookup("rmi://localhost:1099/MsnService");
} catch (Exception e) {
System.out.println("MSN RMI hatası: " + e.getMessage());
}

Thread t = new Thread(this);// yeni bir thread oluştur
t.start();
}

@Override
public void run()
{
while(true) {
try {
list.setListData(msn.mesajAl());
} catch (RemoteException e) {
System.err.println(e.getMessage());
}
}
}

private void initialize() {
this.setSize(684, 400);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}

private JPanel getJContentPane() {
if (jContentPane == null) {
lbl02 = new JLabel();
lbl02.setBounds(new Rectangle(18, 227, 150, 113));
lbl02.setText(" EMRAH");
lbl01 = new JLabel();
lbl01.setBounds(new Rectangle(17, 30, 142, 104));
lbl01.setText(" ERHAN");
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getTxt01(), null);
jContentPane.add(lbl01, null);
jContentPane.add(lbl02, null);
jContentPane.add(getBtn(), null);
jContentPane.add(getList(), null);
}
return jContentPane;
}
}

MsnServer Sınıfı

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class MsnServer {
public MsnServer() {
try {
Registry reg=LocateRegistry.createRegistry(1099);
reg=LocateRegistry.getRegistry();
reg.rebind("MsnService", new MsnImpl());
}
catch (Exception e) {
System.out.println("Trouble: " + e);
}
}

public static void main(String[] args) {
new MsnServer();
}
}