Re: Limit Single Instance



On 2006-01-31, Gordon Beaton penned:
>
> The other typical way is to open a ServerSocket listening on a
> specific port number. If that fails, you can assume your application
> is already running.
>
> This mechanism has two advantages:
>
> - the ServerSocket is automatically released regardless of how the
> application terminates, so no false positives are caused by failure
> to clean up (other applications or users using the same port number
> can still be a problem, so choose wisely).
>
> - a second program instance, upon failing to create the
> ServerSocket, can connect to the original and then exit, thereby
> signalling it to pop up or move to the front.
>
> /gordon

Ah, yes. Good points.

--
monique

Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
.



Relevant Pages

  • Re: A strange error with Sockets
    ... I created a ServerSocket on the first comp, listening to port 5000. ... succesfull connection. ... the Gentoo or Windows laptop, i.e. start server in one window and client in another on the same system. ...
    (comp.lang.java.programmer)
  • Re: java.net.BindException on Mac OS 10.3.4
    ... > when I know for a fact that the port is not in use. ... The error indicates either that there is already a ServerSocket using ... or that you do not have sufficient privileges to bind ... you have accepted a connection and attempt to restart the server while ...
    (comp.lang.java.help)
  • Java Socket Programming
    ... ServerSocket serverSocket = null; ... while (listening) { ... But isn't that port already in use, since that's the port SimpleServer ...
    (comp.lang.java.programmer)
  • Re: How many client sockets bind to a ServerSocket ?
    ... >> I wonder how many client sockets can bind to a ServerSocket. ... > multiplied with the number of client port numbers. ... Steve W. Jackson ...
    (comp.lang.java.programmer)
  • Why is this socket always closed?
    ... Here's a bit of code that has got me puzzled - whatever I do, whatever port ... I choose ), whatever I send to this ServerSocket, I always get ... catch (IOException ioe) ... Princess Morgiah ...
    (comp.lang.java.help)