Networking Programming Options


The System.Net and System.Net.Sockets namespaces offer several options for networking programming. Figure 29-7 shows those options. The easiest way to do network programming is by using the WebClient class. Just a single method of this class is needed to get files from a Web server or to transfer files to an FTP server. However, the functionality of this class is limited. With .NET 2.0, you can use it only with the HTTP and the FTP protocols, and to access files.

image from book
Figure 29-7

The WebClient class itself makes use of the WebRequest and WebResponse classes. These classes have more functionality but are more complex to use.

If you need to create a server you can't use WebClient or WebRequest; you have to use the TcpListener class from the namespace System.Net.Sockets. The TcpListener class can be used to create a server for the TCP protocol, while the TcpClient class is used for writing client applications. With these classes, you are not bound to the HTTP and TCP protocols; you can use any TCP-based protocol.

If you have to use the UDP protocol, you use the UdpListener and UdpClient classes (which are similar to the TcpListener and the TcpClient classes) to write UDP servers and clients.

If you want to be independent of the protocol or require more control of the TCP and UDP protocols, you can do socket programming with .NET. Classes for socket programming are located in the System.Net.Sockets namespace.




Beginning Visual C# 2005
Beginning Visual C#supAND#174;/sup 2005
ISBN: B000N7ETVG
EAN: N/A
Year: 2005
Pages: 278

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