15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

24<br />

networking<br />

WhaT ’ s in This ChaPTer<br />

➤<br />

➤<br />

➤<br />

➤<br />

Downloading fi les from the Web<br />

Using the WebBrowser control in a Windows Forms application<br />

Manipulating IP addresses <strong>and</strong> performing DNS lookups<br />

Socket programming with TCP, UDP, <strong>and</strong> socket classes<br />

This chapter takes a fairly practical approach, mixing examples with a discussion of the relevant<br />

theory <strong>and</strong> networking concepts as appropriate. This chapter is not a guide to computer networking<br />

but an introduction to using the .<strong>NET</strong> Framework for network communication.<br />

You will learn how to use the WebBrowser control in a Windows Forms environment. You will also<br />

learn how the WebBrowser control can make some specifi c Internet access tasks easier to accomplish.<br />

However, the chapter starts with the simplest case, sending a request to a server <strong>and</strong> storing the<br />

information sent back in the response.<br />

This chapter covers facilities provided through the .<strong>NET</strong> base classes for using various network<br />

protocols, particularly HTTP <strong>and</strong> TCP, to access networks <strong>and</strong> the Internet as a client. We cover<br />

some of the lower - level means of getting at these protocols through the .<strong>NET</strong> Framework. You will<br />

also fi nd other means of communicating via these items using technologies, such as the Windows<br />

Communication Foundation (WCF), covered in Chapter 43.<br />

The two namespaces of most interest for networking are System.Net <strong>and</strong> System.Net.Sockets . The<br />

System.Net namespace is generally concerned with higher - level operations, for example, downloading<br />

<strong>and</strong> uploading fi les, <strong>and</strong> making web requests using HTTP <strong>and</strong> other protocols, whereas System.Net<br />

.Sockets contains classes to perform lower - level operations. You will fi nd these classes useful when<br />

you want to work directly with sockets or protocols, such as TCP/IP. The methods in these classes<br />

closely mimic the Windows socket (Winsock) API functions derived from the Berkeley sockets interface.<br />

You will also fi nd that some of the objects that this chapter works with are found in the System.IO<br />

namespace.<br />

Chapters 40 through 42 discuss how you can use <strong>C#</strong> to write powerful, effi cient, <strong>and</strong> dynamic<br />

web pages using ASP.<strong>NET</strong>. For the most part, the clients accessing ASP.<strong>NET</strong> pages will be users<br />

running Internet Explorer or other web browsers such as Opera or Firefox. However, you might<br />

want to add web - browsing features to your own application, or you might need your applications to<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!