Project DescriptionNito.Async is a collection of classes to assist asynchronous programming in .NET, particularly the development and use of classes adhering to the event-based asynchronous pattern.
Developed in C#.
Included ClassesNito.Async includes:
- ActionThread - A child thread with an event-driven main loop sufficient to own and synchronize event-based asynchronous components.
- Timer - A general-purpose timer using the asynchronous event-based model.
- GenericSynchronizingObject - An implementation of ISynchronizeInvoke that uses SynchronizationContext to synchronize.
- CallbackContext - A context manager for asynchronous callbacks.
- AsyncResultEventArgs<T> - An AsyncCompletedEventArgs with a single result value of type T.
- ActionDispatcher - A queue of actions, providing a main loop with a SynchronizationContext for child threads.
- Sync.Synchronize* - Wrappers for various delegate types that provide synchronization using AsyncOperation. These allow fairly easy-to-write translations from the IAsyncResult pattern to the event-based asynchronous pattern.
Nito.Async.Sockets FutureThe current Nito.Async.Sockets API has been frozen. A new (v2) API will be developed that provides better separation between protocol components (e.g., type of message framing, keepalive system, etc., will all be orthogonal). The new API may be based on the Rx framework, expected to be released as part of .NET 4.0.
Nito.Async.Sockets v1 Classes
- IAsyncTcpConnection, ClientTcpSocket, ServerTcpSocket, and ServerChildTcpSocket - Sockets using the event-based asynchronous pattern.
- SocketPacketProtocol - A class that provides a packet protocol for socket connections, including keepalive packets.
- ISimpleAsyncTcpConnection, SimpleClientTcpSocket, SimpleServerTcpSocket, and SimpleServerChildTcpSocket - Sockets using the event-based asynchronous pattern with a packet protocol.
More on Nito.Async.Sockets v1There are three main problems faced by newcomers to TCP/IP:
- Thread synchronization for asynchronous sockets. Most of the TCP/IP functions are designed for maximum performance, leaving the necessary synchronization up to the end users.
- Non-packetized data. Most people read about how TCP/IP uses packets, and they believe that message boundaries are preserved. Local-machine testing confirms this misunderstanding. However, TCP/IP sockets deal with a stream of bytes, not messages.
- Detection of dropped connections. Again, people read about TCP/IP's keepalive packets, but don't realize that they are pretty much useless.
The ClientTcpSocket, ServerTcpSocket, and ServerChildTcpSocket deal with problem (1) by implementing the event-based asynchronous pattern.
The SimpleClientTcpSocket, SimpleServerTcpSocket, and SimpleServerChildTcpSocket handle all three problems by implementing the event-based asynchronous pattern and defining a protocol with message boundaries and automatic keepalive messages.
For more information on TCP/IP socket handling in .NET, see the
TCP/IP .NET Sockets FAQ.