Chapters 37 through 39 discuss how you can use C# to write powerful, efficient, and dynamic Web – pages using ASP.NET.For the most part, the clients accessing ASP.NET pages will be users
running Internet Explorer or other Web browsers such as Opera or Firefox. However, you might want to add Web-browsing features to your own application, or you might need your applications to programmatically obtain information from a Web site. In this latter case, it is usually better for the site to implement a Web service. However, when you are accessing public Internet sites, you might not have any control over how the site is implemented.
This chapter covers facilities provided through the .NET base classes for using various network protocols, particulary HTTP and TCP, to access networks and the Internet as a client. In particular,this chapter covers:
- Downloading files from the World Wide Web
- Using the Web Browser control in a Windows Forms application
- Manipulating IP addresses and performing DNS lookups
- Socket programming with TCP,UDP,and socket classes
This chapter covers some of the lower-level means of getting at these protocols through the .NET Framework. You will also find other means of communicating via these items using technologies,
such as the Windows Communication Foundation (WCF), which is covered in the next chapter.
The two namespaces of most interest for networking are Systerm. Net and System. Net . Sockets. The Sys tern. Net namespace is generally concerned with higher-level operations, for example, downloading and uploading files, and making Web requests using HTTP and other protocols.whereas System.Net. Sockets contains classes to perform lower-level operations. You will find-these classes useful when you want to work directly with sockets or protocols, such as TCP/IP. The methods in these classes closely mimic the Window socket (Winsock)API functions’ derived from the Berkeley sockets interface. You will also find that some of the objects that this chapter works with are found in the System. IO namespace.
This chapter takes a fairly practical approach, mixing examples with a discussion o~the relevant theory and networking concepts as appropriate. This chapter is not a guide to computer networking but an introduction to using the .NET Framework for network communication.
You will learn how to use the Web Browser control in a Windows Forms environment. You will also learn how the Web Browser control can make some specific Internet access tasks easier to accomplish.
However, the chapter starts with the simplest case, sending a request to a server and storing the . information sent back in the response. (As with other chapters, you can download the sample code for this chapter from the CSharp web site at www.csharpaid.com.)