If you want just one connection in total, you could do

public void sessionCreated(IoSession session) throws Exception {
 acceptor.setDisconnectOnUnbind(false);
 acceptor.unbind();
}

public void sessionClosed(IoSession session) throws Exception {
 acceptor.bind();
}

Then your server would only be listening when there is no connection
established.
(you probably need a heartbeat mechanism to ensure that the one and only
connection is still alive)

Maarten

On 2/14/07, James Ladd <[EMAIL PROTECTED]> wrote:

Would it be possible to limit the connections in the accept code by
counting
the
accepted connections and then just not accepting anymore until the count
went
down? The count would go down when a connection closed.

This way, the client would get a connection refused.

I haven't used MINA long enough to tell you if this is possible but
logically from an
NIO perspective it is.

Rgs, James.




>From: Trustin Lee <[EMAIL PROTECTED]>
>Reply-To: [email protected]
>To: [email protected]
>Subject: Re: How do I limit a MINA server to accept just one connection?
>Date: Wed, 14 Feb 2007 10:39:35 +0900
>
>Hi Yigal,
>
>2007-02-13 (화), 14:49 -0800, Yigal Rachman 쓰시길:
> > Hi, Folks:
> >
> > I have just started using MINA, and already love it!
>
>Great!  Please let us know if you have any idea on improving MINA.
>
> > My first application is for an instrument simulator that must accept
> > just one connection at a time.  I have hacked it by immediately
closing
> > a new session if one is already open.  This works ok, but the client
> > gets a "Connection closed by foreign host" message instead of the
> > "connection refused" message I would prefer to see.  I would be
grateful
> > for any suggestions on how to achieve this.
>
>You did the right thing actually.  :)  There's no other way to limiting
>the total number of connection AFAIK.
>
>HTH,
>Trustin
>--
>what we call human nature is actually human habit
>--
>http://gleamynode.net/
>--
>PGP Key ID: 0x0255ECA6


><< signature.asc >>

_________________________________________________________________
Advertisement: Fresh jobs daily. Stop waiting for the newspaper. Search
Now!
www.seek.com.au

http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fninemsn%2Eseek%2Ecom%2Eau&_t=757263760&_r=Hotmail_EndText_Dec06&_m=EXT


Reply via email to