• Post Reply Bookmark Topic Watch Topic
  • New Topic

Socket won't free up even after System.exit()  RSS feed

 
Michael Mendelson
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Howdy, Ranchers.
I'm working on an frame-based app that listens on a socket, and can be turned on or off by a servlet residing on the same machine.
When I test my SocketListener class and invoke it from the command line, everything works OK (messages received and sent). I can start and restart the Listener on the same port.
However when I use the servlet to start the app, the Socket used is not freed up after I exit. When I try to restart the SocketListener on the same port, I get a java.net.BindException.
Here's how the servlet invokes the Socket Listener:

I figured it would be best to put it in its own vm, since it uses System.exit() to quit.
The application is ended by sending a directive ("quit") to the socket. This seems to work fine, whether invoked via the servlet or using a test client application.
Why does the application function differently when invoked using Runtime.exec(), and what can I do about it?
 
Angela Lamb
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does your program call close() on the socket before it exits?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!