Socket Programming in C#
page 3 of 6
by Joydip Kanjilal
Feedback
Average Rating: 
Views (Total / Last 10 Days): 56674/ 132

Synchronous and Asynchronous Communications

In Microsoft .NET, you have support for both synchronous and asynchronous communication using sockets. Incidentally, these are also known as blocking and non-blocking modes of operation. There are subtle differences between the two. When working in the synchronous mode, a method call blocks itself unless the operation is complete in all respects. In the other mode of operation, i.e., the asynchronous mode, a method returns even before its turnaround time has elapsed. Fine, but what is turnaround time? Well, turnaround time refers to the total time taken by a thread to be complete in all respects.

In such a mode of communication, the server application listens to a specific port to receive data from the clients. In doing so, the server application is blocked (for other client requests) unless it receives data from the client application. On the other hand, while operating in the asynchronous mode, the server can process multiple client requests at the same point of time. Note that the asynchronous operations using sockets are typically used for long running tasks. Typical examples of such tasks are opening large files, reading or querying a database with large volumes of data, connecting to a remote computer, accessing resources remotely for long running operations, etc. Further, note that the asynchronous operations actually operate on a separate thread. Typically, applications have two types of threads, application thread and worker thread. An application thread is the main thread of the application; the worker thread is the thread that works in the background to perform asynchronous operations.

Note that the Socket class in the System.Net.Sockets namespace contains both synchronous and asynchronous methods. As an example, while the Connect() and Receive() methods are meant for synchronous operation, the BeginConnect() and EndConnect() methods as well as the BeginReceive() and EndReceive() methods are their asynchronous counterparts.


View Entire Article

User Comments

No comments posted yet.






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2021 ASPAlliance.com  |  Page Processed at 2021-10-20 1:26:53 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search