Chapter 7: IO, Files, and Networking


A computer terminal is not some clunky old television with a typewriter in front of it. It is an interface where the mind and body can connect with the universe and move bits of it about.
— Douglas Adams

A distributed system is a collection of independent computers that appears to its users as a single coherent system.
— Andrew Tanenbaum and Maarten van Steen Distributed Systems: Principles and Paradigms

Overview

Programs need a way of sharing data with other programs and external devices. Without such capabilities, a program would be an entirely isolated black box, never communicating with the outside world. Such an environment might be conducive to solving fixed numerical problems (which never see the light of day), but certainly is not appropriate for 99.999% of the applications built today. The input and output (I/O) libraries of the .NET Framework provide the building blocks using which to break down the walls of an application, facilitating engagement with the outside world.

The Framework's I/O system is built on top of standard Win32 functionality. Rather than having to work with and manipulate file HANDLEs — for example, via calls to OpenFile, ReadFile, WriteFile, and CloseHandle — you are presented with higher-level abstractions that manage HANDLE manipulation transparently. And these same abstractions can be used to interact with the standard input, output, and error streams, and even the network. This eliminates the need to learn with several sets of programming conventions, as is the case in Win32. For purposes of Visual Basic 6 interoperability, the Microsoft.VisualBasic.FileSystem type (found in the Microsoft.VisualBasic.dll assembly) additionally exposes a set of VB6-like interfaces.

The common abstraction weaved across the System.IO and System.Net namespaces is a stream. This fundamental concept enables you to work with bidirectional sources and destinations of data in a general-purpose fashion. Layered on top of streams are readers and writers, tightly encapsulated classes that wrap streams and present an even higher-level interface for programming them. In addition to the basic idea of streams each use in the Framework will be detailed in this chapter, alongside related file-system and network programming features. Specifically, we will discuss how to read and modify attributes of files and directories, communicate via network sockets, Transmission Control Protocol (TCP), and HyperText Transfer Protocol (HTTP), along with a discussion of sending e-mail with the Simple Mail Transport Protocol (SMTP) APIs.




Professional. NET Framework 2.0
Professional .NET Framework 2.0 (Programmer to Programmer)
ISBN: 0764571354
EAN: 2147483647
Year: N/A
Pages: 116
Authors: Joe Duffy

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