Networking in .NET

 < Day Day Up > 



Prior to the advent of the .NET Framework, the ability to develop sophisticated Windows-based networking applications was limited to advanced C++ programmers using the convoluted WinSock library for the most part. There was, of course, the WinInet control that Visual Basic developers could utilize in order to accomplish relatively simple tasks. Other controls were available for other languages. However, one did not have to attempt too much before facing functional impediments with the simple and limited services offered in that control.

Fortunately, the System.Net namespace within the .NET Framework brings a slew of effective functionality packaged in a simple and consistent object model. The ease of use of these classes does not compromise functionality, as almost all the core functions of WinSock 2.0 have been wrapped and abstracted in the System.Net namespace. Developers can easily develop at any level from sockets all the way up to HTTP. Also, unlike the raw use of the WinSock library, the System.Net namespace relieves developers from having the dubious pleasure of manually coding many imperative resource management tasks, such as dealing with overlapped IO and completion ports.

So, without further delay, let's briefly explore the System.Net namespace.

System.Net Namespace

The System.Net namespace actually comprises two namespaces, System.Net and System.Net.Socket.

We will primarily be using the System.Net.Sockets namespace in our application. The layered approach of the System.Net classes provides applications with the ability to access networks with various levels of control based on the demands of the application. In addition to the extensive support for sockets, System.Net classes also offer an impressive array of functionality to use with the HTTP protocol. For the most part, the System.Net offerings are categorized in three layers, Application protocols, Transport protocols, and Web protocols. The System.Net.Sockets namespace consists primarily of classes and utilities for dealing with the transport protocol. Let's look at some of the more important classes within the System.Net namespace, as listed in the table opposite.

Class

Description

Authorization

Provides authentication messaging for a web server.

Cookie

Provides a set of properties and methods used to manage cookies. This class cannot be inherited.

Dns

Simple domain name resolution functionality.

EndPoint

Identifies a network address. This is an abstract class.

GlobalProxySelection

Global default proxy instance for all HTTP requests.

HttpVersion

Defines the HTTP version numbers supported by the HttpWebRequest and HttpWebResponse classes.

HttpWebRequest

HTTP-specific implementation of the WebRequest class.

HttpWebResponse

HTTP-specific implementation of the WebResponse class.

IPAddress

Internet Protocol (IP) address.

IPEndPoint

A network endpoint consisting of an IP address and a port number.

IPHostEntry

Container class for Internet host address information.

NetworkCredential

Provides credentials for password-based authentication schemes such as basic, digest, NTLM, and Kerberos authentication.

SocketAddress

Stores serialized information from EndPoint-derived classes.

SocketPermission

Controls rights to make or accept socket connections.

WebClient

Provides common methods for sending data to and receiving data from a resource identified by a URI.

WebException

The exception that is thrown when an error occurs while accessing resources via the HTTP protocol.

WebPermission

Controls rights to access HTTP Internet resources.

WebPermissionAttribute

Specifies permission to access Internet resources.

WebProxy

Contains HTTP proxy settings for the WebRequest class.

WebRequest

Makes a request to a Uniform Resource Identifier (URI). This class is abstract.

WebResponse

Provides a response from a Uniform Resource Identifier (URI). This class is abstract.

As you can see, the System.Net namespace contains a cornucopia of classes and utilities that are quite useful for a wide range of web and network programming needs.

System.Net.Sockets Namespace

The System.Net.Sockets namespace primarily focuses on the transport layer: the socket layer for which it contains a comprehensive set of classes. These classes do an excellent job of abstracting much of the complexity associated with socket programming, while offering a powerful and productive socket stack that also adheres to the Berkeley socket. Lastly, built-in support for TCP and UDP is well integrated in the classes of the System.Net.Sockets. The table below lists the classes of the System.Net.Sockets namespace.

Class

Description

LingerOption

Contains information about the amount of time it will remain available after closing with the presence of pending data (the socket's linger time).

MulticastOption

Contains IP address values for IP multicast packets.

NetworkStream

Provides the underlying stream of data for network access.

Socket

Implements the Berkeley sockets interface.

SocketException

The exception that is thrown when a socket error occurs.

TcpClient

Provides client connections for TCP network services.

TcpListener

Listens for connections from TCP network clients. This is essentially the TCP server class.

UdpClient

Provides User Datagram Protocol (UDP) network services.

A varying level of control is offered to the developer, such as lower-level classes like the Socket class, and higher-level classes, such as the TcpClient class, which offers slightly less control with added productivity. An in-depth discussion of these classes would go beyond the scope of this book - Professional .NET Network Programming (ISBN 1-86100-735-3) is the ideal book for this, but we will take a closer look at some of the above classes as we design and develop our sample application a little later in this chapter.



 < Day Day Up > 



C# Threading Handbook
C# Threading Handbook
ISBN: 1861008295
EAN: 2147483647
Year: 2003
Pages: 74

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net