Server port not released

Naveen Jain <[email protected]> Tue, 2 Sep 2008 11:27:48 +0530
Newsgroups gmane.comp.java.sun.rmi
Message-ID <EF1BCDE5B64CEC48991CA61DB93D62E50376D15E@eindemw002.eapac.ericsson.se>
Dear RMI Users,

We have an application which binds a service with a particular port and
when we unexport the service, the server port is still not released and
continues to appear in netstat command.

Code 

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

public class RMI  extends UnicastRemoteObject{        
    
    private static RMI rmi;
    protected RMI() throws RemoteException
    {
        super();
    }

    public static void main(String[] args) throws Exception {
       
        try
        {
        int port = 10001;
        String service = "rmi://150.236.120.74" + ':' + port + '/' +
"Pips"; 
        rmi=new RMI();
        LocateRegistry.createRegistry(port);
        Naming.rebind(service, rmi);
        
        Naming.unbind(service);
        UnicastRemoteObject.unexportObject(rmi, true);
        try {
            ServerSocket s = new ServerSocket(port);
            System.out.println("It was fine. service " + service);
        } catch (IOException e) {
            System.out.println("Got an exception in creating
ServerSocket");
            e.printStackTrace();
        }
        }
        catch(Exception e)
        {
            e.printStackTrace();   
        }
    }
    
}

Output

java.net.BindException: Address already in use: JVM_Bind
	at java.net.PlainSocketImpl.socketBind(Native Method)
	at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:359)
	at java.net.ServerSocket.bind(ServerSocket.java:319)
	at java.net.ServerSocket.<init>(ServerSocket.java:185)
	at java.net.ServerSocket.<init>(ServerSocket.java:97)
	at cmg.stdapp.rmicharging.RMI.main(RMI.java:30)


JRE Version : jre1.6.0_07

Please explain the above behavior and what can be done to release the
port 10001 without exiting the application. It is a requirement that we
do not exit the application.


Naveen Jain

This communication is confidential and intended solely for the
addressee(s). Any unauthorized review, use, disclosure or distribution
is prohibited. If you believe this message has been sent to you in
error, please notify the sender by replying to this transmission and
delete the message without disclosing it. Thank you.

E-mail including attachments is susceptible to data corruption,
interception, unauthorized amendment, tampering and viruses, and we only
send and receive emails on the basis that we are not liable for any such
corruption, interception, amendment, tampering or viruses or any
consequences thereof.




===========================================================================
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff RMI-USERS".  For general help, send email to
[email protected] and include in the body of the message "help".

For a list of frequently asked RMI questions please refer to:
http://java.sun.com/j2se/1.3/docs/guide/rmi/faq.html

To view past RMI-USERS postings, please see:
http://archives.java.sun.com/archives/rmi-users.html