I'm trying to make a simple little asynchronous socket server. It accepts
connections, reads and writes, but I can't make it gracefully stop listening.

listener.listen(1)
listener.beginaccept(...)

If before anyone has attempted to connect, I try to stop the listener
socket, I get nasty errors, which I can trap, but it is not obvious that it
has actually stopped or that the asynchronous callback system has been
aborted. This should be trivial. What am I missing?

Re: How to Stop a Listening socket? by Markus

Markus
Thu Jun 29 16:26:09 CDT 2006

rossu wrote:
> I'm trying to make a simple little asynchronous socket server. It accepts
> connections, reads and writes, but I can't make it gracefully stop listening.
>
> listener.listen(1)
> listener.beginaccept(...)
>
> If before anyone has attempted to connect, I try to stop the listener
> socket, I get nasty errors, which I can trap, but it is not obvious that it
> has actually stopped or that the asynchronous callback system has been
> aborted. This should be trivial. What am I missing?

I dont know of another way than to call socket.Close() and catch the
resulting ObjectDisposedException on EndAccept.

hth,
Max

Re: How to Stop a Listening socket? by Jared

Jared
Thu Jun 29 20:41:56 CDT 2006

Hello rossu,

> I'm trying to make a simple little asynchronous socket server. It
> accepts connections, reads and writes, but I can't make it gracefully
> stop listening.
>
> listener.listen(1)
> listener.beginaccept(...)
> If before anyone has attempted to connect, I try to stop the listener
> socket, I get nasty errors, which I can trap, but it is not obvious
> that it has actually stopped or that the asynchronous callback system
> has been aborted. This should be trivial. What am I missing?

How are you stopping the Socket?

--
Jared Parsons [MSFT]
jaredpar@online.microsoft.com
All opinions are my own. All content is provided "AS IS" with no warranties,
and confers no rights.



Re: How to Stop a Listening socket? by rossu

rossu
Fri Jun 30 14:33:02 CDT 2006

listener.close

"Jared Parsons [MSFT]" wrote:

> Hello rossu,
>
> > I'm trying to make a simple little asynchronous socket server. It
> > accepts connections, reads and writes, but I can't make it gracefully
> > stop listening.
> >
> > listener.listen(1)
> > listener.beginaccept(...)
> > If before anyone has attempted to connect, I try to stop the listener
> > socket, I get nasty errors, which I can trap, but it is not obvious
> > that it has actually stopped or that the asynchronous callback system
> > has been aborted. This should be trivial. What am I missing?
>
> How are you stopping the Socket?
>
> --
> Jared Parsons [MSFT]
> jaredpar@online.microsoft.com
> All opinions are my own. All content is provided "AS IS" with no warranties,
> and confers no rights.
>
>
>