7

I'm getting my feet wet in RMI for the first time after working in Java for a number of years, and I'm following this tutorial to get the basics down. The server code below is giving me the following exception saying that port 1099 is already in use, but looking at the output of netstat -ano (on windows), no process is using 1099. I can replace 1099 with any other unused port and it works as expected, with my client program able to connect successfully.

I searched for a while, and this was the nearest thing I could find to someone having the same problem, but he seems to have found the offending process with netstat, which I cannot.

I'm developing in Netbeans, and I get the same exception whether running through Netbeans or executing the JAR on its own. I'm not starting the registry from the command prompt as he seems to be doing, but that doesn't seem to be necessary, as everything goes just fine if I merely change the port number.

What am I missing here?

Server code:

import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;

public class RMIServer {

    public static void main(String[] args) throws InterruptedException {
        try {
            LocateRegistry.createRegistry(1099);
            Naming.rebind("//localhost:1099/MyRemote", new MyRemote());
            System.out.println("Server ready.");
        } catch (Exception ex) {

            System.out.println("Server error:");
            ex.printStackTrace();
        }
    }
}

Exception:

Server error:
java.rmi.server.ExportException: Port already in use: 1099; nested exception is: 
    java.net.BindException: Address already in use: JVM_Bind
    at sun.rmi.transport.tcp.TCPTransport.listen(TCPTransport.java:328)
    at sun.rmi.transport.tcp.TCPTransport.exportObject(TCPTransport.java:236)
    at sun.rmi.transport.tcp.TCPEndpoint.exportObject(TCPEndpoint.java:411)
    at sun.rmi.transport.LiveRef.exportObject(LiveRef.java:147)
    at sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:207)
    at sun.rmi.registry.RegistryImpl.setup(RegistryImpl.java:122)
    at sun.rmi.registry.RegistryImpl.<init>(RegistryImpl.java:108)
    at java.rmi.registry.LocateRegistry.createRegistry(LocateRegistry.java:203)
    at rmiserver.RMIServer.main(RMIServer.java:10)
Caused by: java.net.BindException: Address already in use: JVM_Bind
    at java.net.TwoStacksPlainSocketImpl.socketBind(Native Method)
    at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:376)
    at java.net.TwoStacksPlainSocketImpl.bind(TwoStacksPlainSocketImpl.java:101)
    at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:175)
    at java.net.ServerSocket.bind(ServerSocket.java:376)
    at java.net.ServerSocket.<init>(ServerSocket.java:237)
    at java.net.ServerSocket.<init>(ServerSocket.java:128)
    at sun.rmi.transport.proxy.RMIDirectSocketFactory.createServerSocket(RMIDirectSocketFactory.java:45)
    at sun.rmi.transport.proxy.RMIMasterSocketFactory.createServerSocket(RMIMasterSocketFactory.java:349)
    at sun.rmi.transport.tcp.TCPEndpoint.newServerSocket(TCPEndpoint.java:667)
    at sun.rmi.transport.tcp.TCPTransport.listen(TCPTransport.java:317)
    ... 8 more

Update: Just to be more explicit, here's the complete output of netstat -anp tcp just prior to running the server and getting the exception:

C:\>netstat -anp tcp

Active Connections

  Proto  Local Address          Foreign Address        State
  TCP    0.0.0.0:135            0.0.0.0:0              LISTENING
  TCP    0.0.0.0:445            0.0.0.0:0              LISTENING
  TCP    0.0.0.0:2002           0.0.0.0:0              LISTENING
  TCP    0.0.0.0:5800           0.0.0.0:0              LISTENING
  TCP    0.0.0.0:5900           0.0.0.0:0              LISTENING
  TCP    0.0.0.0:16992          0.0.0.0:0              LISTENING
  TCP    0.0.0.0:16993          0.0.0.0:0              LISTENING
  TCP    0.0.0.0:24800          0.0.0.0:0              LISTENING
  TCP    127.0.0.1:1027         127.0.0.1:24801        ESTABLISHED
  TCP    127.0.0.1:1035         127.0.0.1:2002         ESTABLISHED
  TCP    127.0.0.1:1036         0.0.0.0:0              LISTENING
  TCP    127.0.0.1:1045         127.0.0.1:24801        ESTABLISHED
  TCP    127.0.0.1:1092         0.0.0.0:0              LISTENING
  TCP    127.0.0.1:2002         127.0.0.1:1035         ESTABLISHED
  TCP    127.0.0.1:5152         0.0.0.0:0              LISTENING
  TCP    127.0.0.1:24801        0.0.0.0:0              LISTENING
  TCP    127.0.0.1:24801        127.0.0.1:1027         ESTABLISHED
  TCP    127.0.0.1:24801        127.0.0.1:1045         ESTABLISHED
  TCP    192.168.2.76:139       0.0.0.0:0              LISTENING
  TCP    192.168.2.76:1029      64.74.103.175:443      ESTABLISHED
  TCP    192.168.2.76:1038      192.168.2.220:445      ESTABLISHED
  TCP    192.168.2.76:1042      192.168.2.55:445       ESTABLISHED
  TCP    192.168.2.76:1057      74.125.225.40:443      ESTABLISHED
  TCP    192.168.2.76:1058      74.125.133.95:443      TIME_WAIT
  TCP    192.168.2.76:1060      74.125.142.125:5222    ESTABLISHED
  TCP    192.168.2.76:1063      74.125.225.47:443      ESTABLISHED
  TCP    192.168.2.76:1064      74.125.225.34:443      ESTABLISHED
  TCP    192.168.2.76:1066      74.125.225.47:443      ESTABLISHED
  TCP    192.168.2.76:1082      74.125.142.125:5222    ESTABLISHED
  TCP    192.168.2.76:1138      74.125.225.32:443      TIME_WAIT
  TCP    192.168.2.76:1139      74.125.225.32:443      TIME_WAIT
  TCP    192.168.2.76:1140      173.194.46.37:443      ESTABLISHED
  TCP    192.168.2.76:1143      91.199.212.171:80      CLOSE_WAIT
  TCP    192.168.2.76:1144      178.255.82.1:80        CLOSE_WAIT
  TCP    192.168.2.76:1150      74.125.225.32:443      TIME_WAIT
  TCP    192.168.2.76:1152      198.252.206.16:80      ESTABLISHED
  TCP    192.168.2.76:1153      198.252.206.16:80      ESTABLISHED
  TCP    192.168.2.76:24800     192.168.2.52:15713     ESTABLISHED

Update: I did some more research just on the idea of a port being in use without appearing in netstat (not RMI specific), but this was the only thing that seemed similar, and it's not very helpful. Has anyone else encountered this sort of thing before?

Community
  • 1
  • 1
Kerrigan Joseph
  • 327
  • 1
  • 4
  • 8
  • As noted in the second paragraph, I found that question to be very similar to my issue, except for the fact that he resolved it by finding another process that was using port 1099. Netstat shows me no such process. – Kerrigan Joseph May 22 '13 at 18:04
  • try netstat -o -n -a | findstr 0.0:1099 if when you change it, it works then it is probably in use, unless it is blocked by an antivirus or firewall – Imane Fateh May 22 '13 at 18:17
  • That command returns nothing as well :( I get the same exception even after disabling my firewall entirely. I know so little about the inner workings of RMI, is there something happening behind the scenes that I'm just missing? – Kerrigan Joseph May 22 '13 at 18:29
  • 1
    Nevertheless there is such a process, or you wouldn't have got the exception. – user207421 May 23 '13 at 00:19
  • 3
    Then how would you suggest I identify a process that uses a port without that port appearing in netstat? This is unusual. If an answer was obvious, I wouldn't have asked this question. – Kerrigan Joseph May 23 '13 at 06:28
  • Are you sure there is no 1099 appearing anywhere in `netstat -anp tcp`? Not just as `LISTENING`, as something else? e.g. `ESTABLISHED` or `TIME_WAIT`? – user207421 May 23 '13 at 06:46
  • I'm sure, See my update. Based on other people's dealings with RMI, I'm getting the feeling the real issue here is less of "why isn't RMI working" and more of "how can a process hold a port open without appearing in netstat". – Kerrigan Joseph May 23 '13 at 13:48
  • Exactly. I would reboot and retest. – user207421 May 23 '13 at 23:56
  • netstat doesn't show applications running as other users or root. – user5994461 Feb 04 '19 at 00:37

0 Answers0