ExportException: Port already in use: 1099; nested exception

hi,

Im running a RMI program but every now and then i get the following error. Is there a way to stop this from happening because i kill of all the process in the IDE yet it still comes up with the error. So at the moment i have to restart my PC.

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:310)

at sun.rmi.transport.tcp.TCPTransport.exportObject(TCPTransport.java:218)

at sun.rmi.transport.tcp.TCPEndpoint.exportObject(TCPEndpoint.java:393)

at sun.rmi.transport.LiveRef.exportObject(LiveRef.java:129)

at sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:190)

at sun.rmi.registry.RegistryImpl.setup(RegistryImpl.java:92)

at sun.rmi.registry.RegistryImpl.<init>(RegistryImpl.java:78)

public class ChatServer

{

public ChatServer()

{

try

{

Chat c = new ChatImp();

LocateRegistry.createRegistry(1099);

Naming.rebind("rmi://localhost:1099/chat", c);

}

catch (Exception e)

{

e.printStackTrace();

}

}

public static void main(String args[])

{

new ChatServer();

}

}

Message was edited by:

tbr_84

[1376 byte] By [tbr_84a] at [2007-11-26 14:09:33]
# 1

> Im running a RMI program but every now and then i get

> the following error. Is there a way to stop this from

> happening because i kill of all the process in the

> IDE yet it still comes up with the error. So at the

> moment i have to restart my PC.

This can happen if RMI had accepted any clients in the last two minutes. You don't have to restart your PC, just wait two minutes for all the TIME_WAIT states displayed by 'netstat -a' to disappear.

ejpa at 2007-7-8 1:56:38 > top of Java-index,Core,Core APIs...
# 2
Cheers, that will save me some time.
tbr_84a at 2007-7-8 1:56:38 > top of Java-index,Core,Core APIs...
# 3

> This can happen if RMI had accepted any clients in

> the last two minutes. You don't have to restart your

> PC, just wait two minutes for all the TIME_WAIT

> states displayed by 'netstat -a' to disappear.

I've never seen it on windows (I'm using XP). If I kill a process that listens

on some port (1099 in particular) it is cleared immediately, even if it has accepted connections.

Genady

genadya at 2007-7-8 1:56:38 > top of Java-index,Core,Core APIs...
# 4
There can be accepted connections on port 1099, which have just been closed, and which are still in TIME_WAIT which are unaffected by killing the process. While they exist you can't create a listening socket on port 1099.
ejpa at 2007-7-8 1:56:38 > top of Java-index,Core,Core APIs...
# 5

This is probably off topic ...

I wrote a small test program and even if I get into TIME_WAIT state on a connection, Windows XP (didn't check it on Unix or other windows os) can reuse the server port and listen on it. Maybe Windows relies on TCP sequence numbers or some other magic to tell the connections apart.

(I first created the TIME_WAIT state and then opened the listening socket).

Proto Local Address Foreign AddressState

TCP0.0.0.0:46650.0.0.0:0 LISTENING

TCP127.0.0.1:4665 127.0.0.1:55555TIME_WAIT

genadya at 2007-7-8 1:56:38 > top of Java-index,Core,Core APIs...