Could somebody please point me in the right direction for learning how to do networking in C#/.net 3.5? Code samples and explanations are welcome. Basically I am looking for how
If WCF meets your needs, it's worth looking at. ZeroC and other alternative higher level libraries exist. Otherwise there are several different ways to work closer to the socket level if that's what you need.
These provide a relatively thin wrapper around the underlying sockets. It essentially provides a Stream over the socket. You can use the async methods on the NetworkStream (BeginRead, etc.). I don't like this one as the wrapper doesn't provide that much and it tends to be a little more awkward than using the socket directly.
This provides the classic Select technique for multiplexing multiple socket IO onto a single thread. Not recommended any longer.
The Asynchronous Programming Model (AKA IAsyncResult, Begin/End Style) for sockets is the primary technique for using sockets asynchronously. And there are several variants. Essentially, you call an async method (e.g., BeginReceive) and do one of the following:
The best way is #3 as it is the usually the most convenient. When in doubt, use this method.
Some links:
.NET 3.5 introduced a new model for async sockets that uses events. It uses the "simplified" async model (e.g., Socket.SendAsync). Instead of giving a callback, you subscribe to an event for completion and instead of an IAsyncResult, you get SocketAsyncEventArgs. The idea is that you can reuse the SocketAsyncEventArgs and pre-allocate memory for socket IO. In high performance scenarios this can be much more efficient that using the APM style. In addition, if you do pre-allocate the memory, you get a stable memory footprint, reduced garbage collection, memory holes from pinning etc. Note that worrying about this should only be a consideration in the most high performance scenarios.
For most cases use the callback method of the APM style unless you prefer the style of the SocketAsyncEventArgs / Async method. If you've used CompletionPorts in WinSock, you should know that both of these methods use CompletionPorts under the hood.
In .NET 3.5 world you should definitely learn Windows Communication Foundation - .NET framework for networking.
Useful link:
Synchronous and Asynchronous Operations (in WCF)
You can find useful WCF information on StackOverflow browsing posts tagged with WCF tag
It depends on what you want to focus on.
If you want to focus on functionality and leave the plumbing to the framework, then start with Windows Communication Foundation.
If you're looking to build your own plumbing, then use System.Net.Sockets.Socket
class.