Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / June 2006

Tip: Looking for answers? Try searching our database.

How to Stop a Listening socket?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
rossu - 29 Jun 2006 21:52 GMT
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?
Markus Stoeger - 29 Jun 2006 22:26 GMT
> 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.
[quoted text clipped - 6 lines]
> 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
Jared Parsons [MSFT] - 30 Jun 2006 02:41 GMT
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
[quoted text clipped - 6 lines]
> 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.
rossu - 30 Jun 2006 20:33 GMT
listener.close

> Hello rossu,
>
[quoted text clipped - 16 lines]
> All opinions are my own. All content is provided "AS IS" with no warranties,
> and confers no rights.
Jared Parsons [MSFT] - 30 Jun 2006 22:03 GMT
Hello rossu,

> listener.close

It seems like the option you're looking for here is a way to essentially
cancel the BeginAccept() call.  Unfortunately that is not implemented for
the IAsyncResult pattern.  

You're best option is to differentiate based on the exception when you call
EndAccept.  If it's an ObjectDisposed exception that means that you called
Close on the listener socket someplace else.  Otherwise there was a general
issue when someone attempted to connect to 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.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.