Can a RMI Server trap an exit event of its client  ?

Hi all,
Can a RMI Server trap an exit event of its client ??
For example
If I close the client using Ctrl-C, can the Server known what one of its client is closed ??

You could consider allocating a new remote object per client via some login object. In my book I called this the 'remote session' pattern. That way each client can have its own server-side context, i.e. like an EJB session bean, which can have its own advantages. In fact if you're interested in when a specific client disappears, you must already have some client context so this is a clean solution to that as well.
Then the session object can use the Unreferenced technique to know when the client has gone away unexpectedly, albeit with a 10 minute delay. This can be tuned via the java.rmi.dgc.leaseValue setting at the server. This works because each session object only has one client.
If you can't do this and you can't control the client code, I'm not aware of any other solution under RMI.
Except that as a last resort you could do something really fancy with custom socket factories at both ends that both implement a special ping protocol I suppose, but this is getting pretty hairy and you'd need to understand the RMI wire protocol to make it work.

Similar Messages

  • RMI server behind firewall--must use host as name, not IP

    Server is running behind a firewall, which runs such that any machine behind the firewall cannot use the external IP to get back to itself.
    That is:
    - outside IP = 192.171.20.5 (port forwards 1099 to 192.168.1.5:1099)
    - inside IP = 192.168.1.5 (rmi server listens on 1099)
    from the machine inside (192.168.1.5), it is IMPOSSIBLE to create a socket to [outside ip](192.171.20.5), port 1099, and expect it to get back to the machine inside--the firewall prohibits this.
    I -can- use name-based lookups, such that I can edit the hosts file on the inside box to route (myhost.com to 192.168.1.5). So, if everyone's DNS resolves myhost.com -> 192.171.20.5, then clients anywhere can go to myhost.com:1099 and will be redirected to my internal machine (192.168.1.5:1099).
    The problem with this is that the names get translated to IPs and sent back to the client.
    Is there a way to keep the names as names, so that both client (using external real-world DNS entries) and server (using local hosts file) can both resolve to the proper IP addresses?
    I'm starting server, as follows:
    java -Djava.rmi.server.codebase=http://myhost.com/rmi/ -Djava.security.policy=/policypath/policy -Djava.rmi.server.hostname=myhost.com mypkg.myclass
    The client connects and gets this message (from a connection exception):
    java.rmi.ConnectException: Connection refused to host: 192.168.1.5;

    Server is running behind a firewall, which runs such
    that any machine behind the firewall cannot use the
    external IP to get back to itself.I dont really understand this statement.. Machines behind the firewall referring to the external ip would be going to the gateway, not themselves.. Or do you have an internal AND external ip on the machines behind the firewall? Or are we referring to the gateway machine as an internal machine as well as external?
    That is:
    - outside IP = 192.171.20.5 (port forwards 1099 to
    192.168.1.5:1099)
    - inside IP = 192.168.1.5 (rmi server listens on
    1099)looks good, what kinda OS/firewall? If we're talking linux/ipchains (or iptables) with ip masquerading, I may be of some use to you...
    from the machine inside (192.168.1.5), it is
    IMPOSSIBLE to create a socket to [outside
    ip](192.171.20.5), port 1099, and expect it to get
    back to the machine inside--the firewall prohibits
    this.If you're on the internal network, why can't you just go for the internal ip addr? If I'm understanding correctly, you want internal dns requests for myhost.com to resolve to 192.168.1.5, and external dns requests to resolve to 192.171.20.5? That should't be a problem...
    I -can- use name-based lookups, such that I can edit
    the hosts file on the inside box to route (myhost.com
    to 192.168.1.5). So, if everyone's DNS resolves
    myhost.com -> 192.171.20.5, then clients anywhere can
    go to myhost.com:1099 and will be redirected to my
    internal machine (192.168.1.5:1099).the hosts file has nothing to do with routing, it's simply a dns-type thing... If your dns is giving external users a 192.168 address as the ip for myhost.com, they will never get to it. 192.168 is not routable on the internet, i think most inet routes will drop packets from 192.168.x.x or 10.x.x.x.
    Is there a way to keep the names as names, so that
    both client (using external real-world DNS entries)
    and server (using local hosts file) can both resolve
    to the proper IP addresses?As long as your dns is working correctly, java doesn't care if you use ips or host names.. Hostnames are preferable, so when you change your network around, you wont affect your rmi server.
    I'm starting server, as follows:
    java -Djava.rmi.server.codebase=http://myhost.com/rmi/
    -Djava.security.policy=/policypath/policy
    -Djava.rmi.server.hostname=myhost.com mypkg.myclass
    The client connects and gets this message (from a
    connection exception):
    java.rmi.ConnectException: Connection refused to host:
    192.168.1.5;Is your server compiled with the 192.171 ip? That's not gonna work, you have to use the same IP the server is running on. I'm still not clear on your network layout, is 192.171.20.5 and 192.168.1.5 the 2 gateway ip's, or is 192.168.1.5 a physically different machine? I'd be willing to bet that your server is compiled with the external address, and if that's not the same machine, then there's no chance of that working....
    There's more than port forwarding going on.. IIRC, java rmi keeps track of its own ip's.. A client request to an external ip will not connect to a server running on the internal ip, even if you forward the port, rmi itself doesn't recognize the internal as the ip it's trying to get to (even if it is true), so it bombs out.. This can happen if you run the rmi server on a gateway, and compile the server with the external ip, and try to connect to the internal ip.. If you want external machines to connect, you MUST run the server on an external ip.
    Give a little more info, we'll getcha running... I'm also assuming you have full control of your network (ie, firewall/dns)
    doug

  • XDK 9i Issues : setXSLT - NullPointerException And RMI Server hangs

    Present Scenario :
    JDK 1.3
    Oracle DB : 8.1.6
    JDBC Driver : OracleThin.jar
    XML Parser : xmlparserv2.jar : ( size = 1121488 )
    XML-SQL utility : xsu12.jar : ( size = 180522 )
    We use RMI with JDBC. RMI server object connects to database , uses xsu12.jar and xmlparserv2.jar to convert data into XML. Servlet connects to RMI server and gets this XML. Everything works fine.
    Problem Scenario :
    Since this parser does not support JAXP , I downloaded XDK 9i from oracle site.(9.2.0.1.0 - Dated 01/31/02 ) . After extracting , I replaced xmlparserv2.jar and xsu12.jar with this new ones. And problem started. There are 2 problems :
    A. setXSLT( String, String ) throws NullPointerExcpetion
    B. When I commented setXSLT method, RMI server completes execution of remote method which can be verified from Log. But it never returns , so client gets blocked. When RMI server is stopped by doing ctrl-C , client gets correct XML document.
    Then I installed latest JDBC2.0 driver for 8.1.6 from site which is classes.zip. This also resulted in to same problems mentioned above. But it did work fine wirh earlier version of xmlparserv2.jar and xsu12.jar. Just FYI : I noticed significant size difference betwenn new and old jars.
    New xmlparserv2.jar : size = 660421
    New xsu12.jar : size = 473249
    Thanks for patience
    What could be possible solution ?

    Thanks Jinu
    Problem A of setXSLT throwing NullPOinter Exception is solved. However problem B of RMI server not returning still there.
    Just as an FYI , following is system
    DB : oracle 8.1.6
    xmlparserv2.jar : 9i xdk
    xsu12_816.jar : 9i xdk
    classes12.zip : JDBC2.0 for 8.1.6
    When RMI server is stopped ( ctrl- C ) , client gets correct XML document alongwith proper Node names as set in setStyleSheet( String, String).

  • RMI: multiple clients for one RMI server?

    Hi,
    We're thinking of making a RMI Server.
    However, can multiple clients access the same RMI Server at the same moment?
    So, if one client is connected to the RMI Server, what will happen with the other clients that want to work to do the same thing at the same moment ?

    all over the same port?
    so for example, 100 clients can work simultaneously on this simple server?
    import java.rmi.Remote;
    import java.rmi.RemoteException;
    public interface OkServer extends Remote {
        public String getOk() throws RemoteException;
    import java.rmi.server.UnicastRemoteObject;
    import java.rmi.RMISecurityManager;
    import java.rmi.RemoteException;
    import java.rmi.Naming;
    public class OkServerImpl extends UnicastRemoteObject implements OkServer {
        public OkServerImpl() throws RemoteException {
        public String getOk() {
         return "ok";
        public static void main (String args[]) throws Exception {
              System.setSecurityManager(new RMISecurityManager());
              OkServerImpl OkSvr = new OkServerImpl();
              Naming.bind("OkServer", OkSvr);
    }

  • [Urgent] How to connect RMI Server from EJB

    I'm trying to connect to an RMI server from an EJB. I have client code for the
    RMI Server that already works standalone from the command line. However I am having
    configuration issues with webLogic 6.1 allowing the connection to go through.
    Standalone I create an RMISecurityManager, inside of the EJB I cannot do this.
    How do I set up WL6.1 to allow RMI connections?
    Injae Lee

    Some threads already posted :
    Can Forms 10g access data from non-ORacle database?
    Re: connect form to mysql server
    Greetings....
    Sim

  • RMI Server exits early when using SSL

    Hi,
    Maybe someone else has encountered this one.
    My RMI server works fine when I use standard sockets. I create an instance and bind it into the rmiregistry. It then waits indefinitely for connections.
    When I use SSL, I can create the object instance. I can also bind it into the registry. However, it only waits a few seconds and then exits.
    No exception or error is thrown (I have a catch Throwable block on my main method to be sure of this.)
    As my code is adapted from the RMI SSL 'Hello World' examples found on this site) I decided to compile and run those examples. I get the same problem.
    Any ideas?
    This is the relevant part of my code:
    public static void main(String[] args)
        HelloImpl obj = null;     
        try
            // use -clear option to get standard sockets
            if (args.length > 0 && args[0].equals("-clear"))
                obj = new HelloImpl();                   
            else // otherwise default to SSL sockets
                RMIClientSocketFactory csf = new RMISSLClientSocketFactory();
                RMIServerSocketFactory ssf = new RMISSLServerSocketFactory();
                obj = new HelloImpl(csf,ssf);               
            Naming.rebind("HelloServer", obj);
            System.out.println("HelloServer listening for requests\n";
        catch (RemoteException ex)
            ex.printStackTrace();
        catch (MalformedURLException ex)
            ex.printStackTrace();
        catch (Throwable ex)
            ex.printStackTrace();

    Thanks for taking an interest.
    I just use:
    c:\j2sdk1.4.1_02\bin\rmiregistry
    to start the registry.
    I think the problem is with my SSL sockets. I'm guessing the reason a UnicastRemoteObject is normally kept alive (not garbage collected) in the registry is because it has a ServerSocket which is waiting for connections.
    In this case, I don't think the SSLServerSocket is getting created and so my UnicastRemoteObject gets garbage collected.
    However, I'm not sure why exactly.

  • What kind of server can host RMI

    I am trying to use RMI, however there are some simple question about the server type I want to ask. A. Is it possible to use a http server like www.myschoolurl.edu/~mypage? I can only access the root directory of ~mypage in a unix system. B. Can I use Windows 2000 professional's default Server to host RMI if I have a unique IP? How?
    Thanks

    Hi
    Im afraid i do not understand your question but i will try to explain the basic concept of the RMIRegistry which is the part of the 'RMI Server concept' which binds itself on a port.
    The RMIRegistry is a mapping mechanism which maps a identifier (a 'String' in java) to a Object which has methods (defined in the interface) which you can call from a remote host.
    So.. this RMI Server says:
    If somebody wants to to have 'Object1' (called a 'lookup') the server searches the object and if it is availible, he will return it to the caller.
    About the server type: you can run the rmi server anywhere where you can run java.
    You can start this rmiregistry with a java method or start a seperate registry via the 'rmiregistry' binary.
    for example: on windows you can start it with: start rmiregistry.. on unix ./rmiregistry &
    (this binaray is located in $JAVA_HOME/bin)
    as far as i know there are possibilities to use rmi over HTTP.
    one example uses SOAP (simple object access protocol) which uses xml to transport the information...
    i hope this helps...
    greets
    mike

  • Can I put both RMI server and client in a same program

    hi everybody...
    I wanna know that can I use RMI server and client in a same program....My idea is like that I wanna use the same program for client and server....When I open my program, I can accept connection from other program and if I want to connect to others, I can also connect it. I expect you to understand my question. Here are the sample code for my program...
    package Chat.Rmi;
    import java.lang.*;
    import java.util.*;
    import java.rmi.*;
    import javax.swing.*;
    import java.net.*;
    import java.rmi.server.*;
    import java.rmi.registry.*;
    public class netKitManager implements netKitInterface{
        public netKitManager(){
            try{
            reg = LocateRegistry.createRegistry(4242);
            reg.rebind("NetKitServer",this);
            }catch(RemoteException re){
        public void DirectConnect(String ip){
            try{
            netUser = (netKitInterface) Naming.lookup("rmi://"+ip+":4242/NetKitServer");
            JOptionPane.showMessageDialog(null,"Connection succeded!");
            }catch(NotBoundException nbe){
                JOptionPane.showMessageDialog(null,"There is no server at specified IP address!");
            }catch(MalformedURLException mue){
                JOptionPane.showMessageDialog(null,"IP adress may be wrong!");
            }catch(RemoteException re){
                JOptionPane.showMessageDialog(null,"Remote exception occured!");
        public void SendMessage(String msg){
            try{
            netUser.SetMessage(msg);
            }catch(RemoteException re){
        public void SetMessage(String msg) throws RemoteException{
            chatKit.SetMessage(msg);
        private netKitInterface netUser;
        private Hashtable netUserList;
        private Registry reg;
    }

    Yes it can be done. I have done it.

  • Can't start RMI server using JAR file

    I found it interesting that if I start my RMI server from
    a plain directory, everything goes fine.
    But if I jar all these necessary files into a jar file,
    and start my RMI server with command below
    java -jar server.jar
    UnmarshalException and ClassNotFoundException are
    thrown to indecate that my stub class can't be found
    (which I'm sure my stub class is in jar file)
    Why is jar file so special that it can't act like
    what it originally does when it hasn't been jared?
    or I really should take care of some configuration
    before I really can run a jar file?
    thanks

    To clarify few things...
    What I don't understand is that when I convert all my
    directories and class files properly into the jar file, they
    just can't work properly.
    I don't know if it's a problem of JAR file,
    or it's RMI that make this JAR file special?
    I'll simulate my JAR file structure that listed below,
    these structure works fine when they have'nt been
    converted into JAR file.
    META-INF/
    META-INF/MANIFEST.MF
    a/b/x1.class
    a/b/x2.class
    a/b/c/Y.class
    a/b/c/Y_Skel.class
    a/b/c/Y_Stub.class
    And when I use command "java -jar server.jar"
    to run my application, ClassNotFound exception
    is thrown to indecate my stub class is not found.
    Is there anything I can do to correct this?
    thanks

  • RMI server exits after 10 minutes

    Hi
    I have a strange problem: The rmi server exits after about 15 minutes when using my own socket factories. The reason seems to be, that only daemon threads are left in the servers VM.
    If I add code like:
    while(true) {
    try {
    Thread.sleep(10000000);
    } catch(Exception e){}
    to the main method, the server continues to run as desired, the main thread is not a daemon thread.
    I checked the accept method of my factory, it runs in a daemon thread.
    Is there any configuration property to specify that the server should run forever?
    BTW: the server does not exit when using no own socket factories.

    No, I don't export manually. However, isn't that the job of the naming service?
    Calling export causes an "Object already exported" exception.
    Here is the complete working main code that starts the server (removing the endless loop will cause the server VM to terminate after about 15 minutes of inactivity):
    public static void main(String args[]) throws Exception
    TClientSocketFactory client = new TClientSocketFactory();
    TServerSocketFactory server = new TServerSocketFactory();
    client.setServiceName("authtest");
    server.setServiceName("authtest");
    AuthImpl obj = new AuthImpl(client, server);
    Naming.rebind(
    "//" + InetAddress.getLocalHost().getHostName() + "/AuthServer",
    obj
    while(true) {
    try {
    Thread.sleep(10000000);
    } catch(Exception e){}
    Cheers...Urs

  • What can't client connect to RMI server on same machine?

    I'm trying to get a client to connect to an RMI server that resides on the same machine, but it's not working. When run, I get the following exception:
    java.rmi.ConnectException: Connection refused to host: 121.0.0.55; nested exception is:
    java.net.ConnectException: Connection refused
    java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:320)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:133)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:120)
    at java.net.Socket.<init>(Socket.java:273)
    at java.net.Socket.<init>(Socket.java:100)
    at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:25)
    The machine in question is a Solaris 8 system running Java 1.3. I've checked all the networking permissions, and they seem to be ok. Any ideas as to what might be causing this?

    Thanks for the reply! Dumb question: How do I start the registry? I see debugging code that indicates that the server is [probably] being started.
    Usually this means that the registry isn't running or
    the server isn't running.

  • RMI Server Offline Problem

    Hello all, I am e newbie in the world of RMI programming. I have developed an application that can control two devices over the internet. The code files are given below :
    Parallel.java
    import java.rmi.*;
    public interface Parallel extends Remote
         void relayDriver(byte k) throws RemoteException;
         byte currentStatus() throws RemoteException;
    ParallelImpl.java
    import parport.ParallelPort;
    import java.rmi.*;
    import java.rmi.server.*;
    public class ParallelImpl extends UnicastRemoteObject implements Parallel
         private Byte ctrlValue;
         ParallelPort lpt1 = new ParallelPort(0x378); // 0x378 is normally the base address for the LPT1 port
         public ParallelImpl(byte a) throws RemoteException
              ctrlValue = a;
              lpt1.write(ctrlValue);
              System.out.println("Device Actuation Code "+ctrlValue);
         public void relayDriver(byte k) throws RemoteException
              ctrlValue = k;
              System.out.println("Device Actuation Code "+ctrlValue);
              lpt1.write(ctrlValue);
         public byte currentStatus() throws RemoteException
    return ctrlValue;
    ParallelClient.Java
    import java.io.*;
    import java.rmi.*;
    import java.rmi.server.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class ParallelClient extends JApplet implements ActionListener
         Byte g;
         String url = "rmi://169.254.196.149/";
         private Container container;
         private javax.swing.JTextArea resultArea;
         public void init()
              container = getContentPane();
              container.setLayout( new BorderLayout() );
              resultArea = new javax.swing.JTextArea();
              JRadioButton buttonZero = new JRadioButton("No Device
    On");
         buttonZero.setMnemonic(KeyEvent.VK_A);
         buttonZero.setActionCommand("0");
         buttonZero.setSelected(true);
         JRadioButton buttonOne = new JRadioButton("Device 1 On
    Only");
         buttonOne.setMnemonic(KeyEvent.VK_B);
         buttonOne.setActionCommand("1");
         JRadioButton buttonTwo = new JRadioButton("Device 2 On
    Only");
         buttonTwo.setMnemonic(KeyEvent.VK_C);
         buttonTwo.setActionCommand("2");
         JRadioButton buttonThree = new JRadioButton("Device 1
    and 2 Both On");
         buttonThree.setMnemonic(KeyEvent.VK_D);
         buttonThree.setActionCommand("3");
         //Group the radio buttons.
         ButtonGroup group = new ButtonGroup();
         group.add(buttonZero);
         group.add(buttonOne);
         group.add(buttonTwo);
         group.add(buttonThree);
         //Register a listener for the radio buttons.
         buttonZero.addActionListener(this);
         buttonOne.addActionListener(this);
         buttonTwo.addActionListener(this);
         buttonThree.addActionListener(this);
              JPanel radioPanel = new JPanel(new GridLayout(0, 1));
         radioPanel.add(buttonZero);
         radioPanel.add(buttonOne);
         radioPanel.add(buttonTwo);
         radioPanel.add(buttonThree);
         container.add(radioPanel, BorderLayout.LINE_START);
              container.add(resultArea, BorderLayout.SOUTH);
         public void actionPerformed(ActionEvent e)
              try
                   Parallel r1 = (Parallel)Naming.lookup(url +
    "inival");
                   if(r1.currentStatus()==0)
                             resultArea.setText("Previous
    Status: No Devices Online....");
                        else if(r1.currentStatus()==1)
                             resultArea.setText("Previous
    Status: Device 1 Online. Device 2 Offline.");
                        else if(r1.currentStatus()==2)
                             resultArea.setText("Previous
    Status: Device 2 Online. Device 1 Offline.");
                        else
                             resultArea.setText("Previous
    Status: Device 1 & 2 both are Online.");
                   g = Byte.parseByte(e.getActionCommand());
                   r1.relayDriver(g);
                   if(r1.currentStatus()==0)
                             resultArea.setText("Current
    Status: No Devices Online....");
                        else if(r1.currentStatus()==1)
                             resultArea.setText("Current
    Status: Device 1 Online. Device 2 Offline.");
                        else if(r1.currentStatus()==2)
                             resultArea.setText("Current
    Status: Device 2 Online. Device 1 Offline.");
                        else
                             resultArea.setText("Current
    Status: Device 1 & 2 both are Online.");
              catch(Exception et)
                   resultArea.setText("Server OffLine");
    ParallelServer.java
    import java.io.*;
    import java.rmi.*;
    import java.rmi.server.*;
    public class ParallelServer
         public static void main(String args[])
              try
                   System.out.println("Constructing Server Implementations ....");
                   ParallelImpl p1 = new ParallelImpl((byte)0);
                   System.out.println("Binding Server Implementation to registry ....");
                   Naming.rebind("inival",p1);
                   System.out.println("Waiting for invocations from Client ....");     
              catch(Exception e)
                   System.out.println("Server is Offline or Line has broken. Error : "+ e);
    The corresponding stub files, class files have been loaded on the internet. http://rcviproject.110mb.com/
    On the server machine the rmi registry is on and the ParallelServer program is also running. But when the applet at the URL is actuated then it shows 'server offline'. Why is this happening? Please help.

    That did not print anything. The server when started by the following commands :
    start rmiregistry
    start java ParallelServer
    continues to run at Waiting for invocation from client ...... no error msg is shown.
    do i need tomcat on the server machine in addition to this ?

  • Rmi server problem

    hi
    Can anybody tell me how to stop the Jvm to free the Rmi server port and the remote object?

    Hi,
    The first step: unbind the bound object from the registry!
    As far as I know the UnicastRemoteObject calls the exportObject() method in its constructor. If you want to force the unregistering call the UnicastRemoteObject's unexportObject() method on the server object.
    After these two calls (Naming.unbind(), UnicastRemoteObject.unexportObject()) the server object surely is no longer listening the remote calls, the JVM exits smothly...
    Sany

  • Kicking out a client from rmi server

    I have a few clients on a rmi server .
    how can I disconnect a client from the server?
    the client is an applet.
    I treid calling a method containning System.exit(0)
    from the server on to the client but it throws a
    java.securtiy .. exception?
    so how can I close down the client applet from the server?
    thanks

    please help
    shall I throw a remote exception on the server

  • [RMI] server/client, help me.

    I have done a Chat with RMI, between a server and a client machine on my network.
    The server start normaly, and the client manage to connect the server, but the server failed to connect the client.
    Can Someone explain me why?
    Here are the source files:
    *********Client Distant****************
    import java.rmi.*;
    public interface ClientDistant extends java.rmi.Remote {
    public void msg(Message m) throws RemoteException;
    **********Client DistantImplementation**************
    import java.io.*;
    import java.net.*;
    import java.rmi.*;
    import java.rmi.server.*;
    import java.rmi.registry.*;
    import java.net.MalformedURLException;
    public class ClientDistantImpl extends java.rmi.server.UnicastRemoteObject implements ClientDistant, Runnable {
    String nom;
    String nomServeur;
    /** Constructs ClientDistantImpl object and exports it on default port.
    public ClientDistantImpl(String nom, String nomServeur) throws RemoteException {
    super();
    this.nom = nom;
    this.nomServeur= nomServeur;
    Thread leThread = new Thread(this);
    leThread.start();
    /** Register ClientDistantImpl object with the RMI registry.
    * @param name - name identifying the service in the RMI registry
    * @param create - create local registry if necessary
    * @throw RemoteException if cannot be exported or bound to RMI registry
    * @throw MalformedURLException if name cannot be used to construct a valid URL
    * @throw IllegalArgumentException if null passed as name
    public static void registerToRegistry(String name, Remote obj, boolean create) throws RemoteException, MalformedURLException{
    if (name == null) throw new IllegalArgumentException("le nom doit etre non vide");
    try {
    Naming.bind(name, obj);
    } catch (AlreadyBoundException ex){
              throw new IllegalArgumentException("le nom est deja utilise");
    } catch (RemoteException ex){
    if (create) {
    Registry r = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
    r.rebind(name, obj);
    } else throw ex;
    /** Main method.
    public static void main(String[] args) {
    System.setSecurityManager(new RMISecurityManager());
    try {
    BufferedReader entree = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Entrez votre nom");
    String nom = entree.readLine();
    System.out.println("Entrez le nom de la machine serveur");
    String nomServeur = entree.readLine();
    ClientDistantImpl obj = new ClientDistantImpl(nom, nomServeur);
    String machineLocale = InetAddress.getLocalHost().getHostAddress();
                   System.out.println("Machine locale : "+machineLocale);
                   String[] tab = Naming.list("//"+nomServeur);
                   for(int i=0; i<tab.length; i++)
                        System.out.println(tab[i] + " est enregistre sur le registre du serveur");
    ServeurChat sc = (ServeurChat) Naming.lookup("//"+nomServeur+"/serveurChat");
    String url = "//"+machineLocale+"/"+nom;
    sc.connect(url);
    System.out.println("Entrez vos messages en terminant par FIN");
    String mess = entree.readLine();
    while(!mess.equalsIgnoreCase("FIN")) {
    Message m = new Message(url, mess);
    sc.msg(m);
    mess = entree.readLine();
    sc.disconnect(url);
              System.exit(1);
    } catch (Exception ex) {
    ex.printStackTrace();
    public void msg(Message m) throws RemoteException {
    System.out.println(m);
    public void run() {
    try {
    registerToRegistry(nom, this, true);
    } catch (Exception ex) {
    ex.printStackTrace();
              System.exit(1);
    ****************Serveur Chat********************
    import java.rmi.*;
    public interface ServeurChat extends ClientDistant {
    public void connect(String url) throws RemoteException;
    public void disconnect(String url) throws RemoteException;
    *****************Serveur Chat Implementation**********
    import java.net.*;
    import java.util.*;
    import java.rmi.*;
    import java.rmi.server.*;
    import java.rmi.registry.*;
    import java.net.MalformedURLException;
    /** Unicast remote object implementing ServeurChat interface.
    * @author Patrice Torguet
    * @version 1.0
    public class ServeurChatImpl extends UnicastRemoteObject implements ServeurChat {
    Vector clients;
    /** Constructs ServeurChatImpl object and exports it on default port.
    public ServeurChatImpl() throws RemoteException {
    super();
    clients = new Vector();
    public static void registerToRegistry(String name, Remote obj, boolean create) throws RemoteException, MalformedURLException{
    if (name == null) throw new IllegalArgumentException("registration name can not be null");
    try {
    Naming.rebind(name, obj);
    } catch (RemoteException ex){
    if (create) {
    Registry r = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
    r.rebind(name, obj);
    } else throw ex;
    /** Main method.
    public static void main(String[] args) {
    System.setSecurityManager(new RMISecurityManager());
    try {
    String machineLocale = InetAddress.getLocalHost().getHostName();
    System.out.println("Nom du serveur = serveurChat");
    ServeurChatImpl obj = new ServeurChatImpl();
    registerToRegistry("serveurChat", obj, true);
    } catch (Exception ex) {
    ex.printStackTrace();
    public void disconnect(String url) throws RemoteException {
    clients.removeElement(url);
    public void msg(Message m) throws RemoteException {
    Enumeration e = clients.elements();
    String url = null;
    while(e.hasMoreElements()){
    try {
    url = (String) e.nextElement();
    if (!url.equalsIgnoreCase(m.url)) {
    ClientDistant cl = (ClientDistant) Naming.lookup(url);
    cl.msg(m);
    } catch(Exception ex) {
    ex.printStackTrace();
    clients.removeElement(url);
    public void connect(String url) throws RemoteException {
    clients.addElement(url);
    *************Message*********************
    import java.io.*;
    * @author Patrice Torguet
    * @version
    public class Message implements Serializable {
    String url;
    String msg;
    /** Creates new Message */
    public Message(String url, String msg) {
    this.url = url;
    this.msg = msg;
    public String toString() {
    return url + " : " + msg;
    Thx for help.

    This is the exception:
    java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
    java.net.ConnectException: Connection refused
    java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:350)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:137)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:124)
    at java.net.Socket.<init>(Socket.java:268)
    at java.net.Socket.<init>(Socket.java:95)
    at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:20)
    at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:115)
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:494)
    at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185)
    at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:169)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:78)
    at ServeurChatImpl_Stub.connect(Unknown Source)
    at ClientDistantImpl.main(ClientDistantImpl.java:85)

Maybe you are looking for

  • NPE creating a new session on WebLogic Server 9.2

    We're getting the following stack trace from WebLogic Server 9.2 when a page gets hit. It appears to be a clustering error when creating a new session. When there is only a single server left running, the pages are served correctly. Any thoughts appr

  • How to localize LiveCycle Form in different languages ?

    Dear All, I want to localize the captions of the fields in PDF Form developed using Adobe LiveCycle Designer 7.1. In order to do that, I figured out that have to prepare XML Data Source of all Captions and related text in the target language. The lan

  • How to allow page visitors to download a whole photo album

    hi guys i think i have seen on mobile.me hosted websites an option to allow visitors to download a whole photo album as a zipped file. i would like to offer the same to my visitors but host my site not at mobile.me but a private hosting company. is t

  • Reservations not updated in Oracle

    Hello, I want to see if somebody can help me with this issue i have.... I have a Sales Order which already has the 'CLOSED' status, but if I go into the reservations window, I still see the lines that are inside the S.O. My quesion is....what shoud I

  • Planned /actual cost report in iw31

    Hi Gurus Is there any method to see individual component cost while creating order (IW31)  in pm. I tried with planned/cost report button on the cost tab by including material and material text  in the layout, but when I execute the material and text