Re: Server port not released
Niclas Hedhman <[email protected]> Tue, 2 Sep 2008 07:35:38 +0100
| Newsgroups | gmane.comp.java.sun.rmi |
|---|---|
| Message-ID | <[email protected]> |
Hi, RemoteObjects are not bound to the port 10001 in your example. It is the bootstrapping mechanism (Registry) that takes the port, so unexport() is not closing port per definition. Instead, ports are normally allocated dynamically and anonymously, and re-used across remote objects. I can't recall the algorithm, but essentially new ports are created per RMI SocketFactory pairs and number of concurrent method calls from the same client. These ports are garbage collected when no remote objects are using them. Since, Registry is "just another Remote Object" the same principle applies. You need to unexport the Registry to shut it down. UnicastRemoteObject.unexportObject( registry, true ); Also note that it is not necessary to use Registry at all. You can use JNDI or custom methods to pass the serialized stub to the client, including http and even email. Cheers Niclas On Tue, Sep 2, 2008 at 6:57 AM, Naveen Jain <[email protected]> wrote: > 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 > =========================================================================== 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