MSDN Archive Home
Help and FAQs
All Resource Updates
Change History (all pages)
Note: Now Hosted on CodePlex
Version 1.4 and newer are hosted on
Resource Page Description
Makes use of the Nito.Async library to demostrate client and server TCP/IP sockets capable of sending and receiving objects as well as detecting dropped connections.
The sample server:
The sample client:
More on Nito.Async.Sockets
There 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.
The binaries for Nito.Async.Sockets (and Nito.Async) are included in the release of this sample code. They may also be downloaded (with source) from
Socket example code
The "LowerLevel" example code uses ClientTcpSocket and ServerTcpSocket for thread synchronization, uses Nito.Async.Sockets.SocketPacketProtocol to define a protocol with message boundaries, and uses a timer to send keepalive messages.
The "Simple" example code uses SimpleClientTcpSocket and SimpleServerTcpSocket to provide the same functionality with less coding.
However, the Simple*Socket classes cannot be used to communicate with systems that do not use the same socket packet protocol. So, "LowerLevel" should be used as a starting point to communicate with other systems, but "Simple" should be used as a starting point when developing both the client and server ends.
Both examples demonstrate how to send objects over the network as messages. They are capable of sending a simple string message as well as a "complex" message which includes a GUID, DateTime, and a string. The message types are defined in a dll that is referenced by both client and server.
Both examples also include a function for retrieving all the IPv4 addresses of a computer (though this is not necessary for network communication).
Sep 23 2009 at 3:07 AM
, version 5
Apr 25 2011 at 10:55 AM
Sign in to add a comment
Version 1.4 and newer ...
Tue Sep 22 2009 at 7:00 AM
More Tags ...
Visual Studio 2005
Visual Studio 2008
Visual Studio 2010
Manage Your Profile
MSDN Flash Newsletter
© 2008 Microsoft Corporation. All rights reserved.