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 / April 2005

Tip: Looking for answers? Try searching our database.

Asynchronous operations with System.Net.Sockets

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nate A - 28 Apr 2005 00:23 GMT
I have a couple questions concerning the inner workings of a
System.Net.Socket class when doing asynchronous read/write operations.

1) When a program calls the asynchronous operation BeginRead(..., callback)
or BeginWrite(..., callback), the reading or writing operation obviously runs
on a separate thread created and maintained inside of the the Net.Socket
object. My question is, when the read/write operation completes and the
"callback" gets called, does the code within the callback execute on that
same thread that the Socket created to do the actual reading/writing, or does
it do the callback on separate worker thread created by the socket, thereby
freeing the socket object to handle other calls to BeginRead/Write while the
callback code is executing?

2) On a Net.Socket, after calling BeginWrite(...), if your program calls
BeginWrite(...) again to write more data BEFORE the first BeginWrite
completes and executes the callback (and subsequently calls EndWrite(...)),
will the data in the second BeginWrite be "queued up" by the socket and
automatically send after an EndWrite(...) is called when the first write
completes? You'd think I'd be able to figure this out though trial and error
testing, but my results were somewhat confusing and although calling
BeginWrite a second time before the first BeginWrite completes does not throw
an error, it was hard to tell if the data in-fact was queued by the socket
and send immediately after the first write completed. Because of this I
decided to write a wrapper class that allows requests to write data from
multiple threads, and the class queues each write request on a Queue object
and processes the next queued write after the previous one completes. I'd
much rather not have to use the wrapper class if someone could convince me
the Net.Socket class can queue up the data to write upon each successive call
to BeginWrite.

Thanks,
Nate A
Feroze [msft] - 30 Apr 2005 00:02 GMT
Yes, when the Callback is executed, it is executed on a separate thread from
the one that initiated the asynchronous operation.

You can queue up as many beginXXX as you want, and they will be completed in
the order they were queued to the OS. If the BeginXXX did not throw an
exception, you can assume that the operation was queued. If a queued
operation fails, then your callback will be invoked and you will get an
exception in the corresponding call to EndXXX().

Does that help?

Signature

feroze

-----------------
This posting is provided as-is. It offers no warranties and assigns no
rights.

See http://weblogs.asp.net/feroze_daud for System.Net related posts.
----------------

>I have a couple questions concerning the inner workings of a
> System.Net.Socket class when doing asynchronous read/write operations.
[quoted text clipped - 38 lines]
> Thanks,
> Nate A

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.