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.