Pro .NET 1.1 Network Programming Second Edition978-1-4302-0660-6/1.pdf · The information in this...
Transcript of Pro .NET 1.1 Network Programming Second Edition978-1-4302-0660-6/1.pdf · The information in this...
Pro .NET 1.1 Network Programming
Second Edition
CHRISTIAN NAGEL, AJIT MUNGALE, VINOD KUMAR, NAUMAN LAGHARI, ANDREW KROWC2YK,
TIM PARKER, SRINIVASA SIVAKUMAR, AND ALEXANDRU SERBAN
APress Media, LLC
Pro .NET 1.1 Network Programming, Second Edition
Copyright © 2004 by Christian Nagel, Ajit Mungale, Vinod Kumar, Nauman Laghari, Andrew Krowczyk, Tim Parker, Srinivasa Sivakumar, and Alexandru Serban
Originally published by Apress in 2004
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher.
ISBN 978-1-59059-345-5 ISBN 978-1-4302-0660-6 (eBook) DOI 10.1007/978-1-4302-0660-6
Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.
Lead Editor: Dominic Shakeshaft Technical Reviewer: Alexandru Serban Editorial Board: Steve Anglin, Dan Appleman, Ewan Buckingham, Gary Cornell, Tony Davis, Jason
Gilmore, Chris Mills, Dominic Shakeshaft, Jim Sumser Project Manager: Sofia Marchant Copy Edit Manager: Nicole LeClerc Copy Editors: Marilyn Smith, Ami Knox Production Manager: Kari Brooks Production Editor: Janet Vail Compositor and Artist: Diana Van Wmkle Proofreader: Greg Teague Indexer: Brenda Miller Cover Designer: Kurt Krames Manufacturing Manager: Tom Debolski
The information in this book is distributed on an "as is" basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work.
The source code for this book is available to readers at http: I lwww. a press. com in the Downloads section. You will need to answer questions pertaining to this book in order to successfully download the code.
Contents at a Glance
About the Authors ................................................................. xv
About the Technical Reviewer ...................................................... xvii
Introduction ...................................................................... xix
HAPTER 1 HAPTER 2
CHAPTER 3
CHAPTER 4
HAPTER 5
HAPTER 6
Networking Concepts and Protocols ............................. 1
Streams in .NET ............................................... 45
Network Programming in .NET ................................. 85
Socket Programming in .NET .................................. 121
Raw Socket Programming .................................... 163
1Pv6 .......................................................... 189
TCP .......................................................... 213
CHAPTER 8 UDP .......................................................... 263
HAPTER 9 Multicast Sockets ............................................ 295
CHAPTER 10 HTIP ......................................................... 345
CHAPTER 11 E-mail Protocols .............................................. 393
CHAPTER 12 Cryptography in .NET ......................................... 431
CHAPTER 13 Authentication Protocols ...................................... 475
INDEX ....................................................................... 501
IIi
Contents
About the Authors ................................................................. xv
About the Technical Reviewer ...................................................... xvii
Introduction ...................................................................... xix
HAPTER 1 Networking Concepts and Protocols ....................... 1
The Physical Network ............................................. 2 WAN Lines .................................................. 2 Ethernet .................................................... 3
Physical Components ........................................ 5 The Layered OSI Model .......................................... 11
Layer 1 : Physical Layer ...................................... 13
Layer 2: Data Link Layer. .................................... 13 Layer 3: Network Layer. ..................................... 14 Layer 4: Transport Layer ..................................... 14 Layer 5: Session Layer ...................................... 15 Layer 6: Presentation Layer .................................. 15 Layer 7: Application Layer ................................... 15
Network Protocols ............................................... 16 Basic Protocols ............................................. 16 Internet Protocols ........................................... 27 E-mail Protocols ............................................ 32 Other Application Protocols .................................. 33
Sockets ........................................................ 34 Domain Names ................................................. 35
Whois Service .............................................. 36 Domain Name Servers ...................................... 36
The Internet .................................................... 37 lntranets and Extranets ...................................... 38 Firewalls .................................................. 38 Web Proxies ............................................... 39 XML Web Services .......................................... 40
.NET Remoting .................................................. 41 Messaging ..................................................... 42 Other Ways to Access Network Objects ............................. 43 Internet Organizations and Standards .............................. 43 Summary ...................................................... 44 v
CHAPTER 2 Streams in .NET ............................................. 45
Streams in .NET ................................................. 45 Synchronous and Asynchronous 1/0 ........................... 45
Stream Class ............................................... 46 FileStream Class ........................................... 50 Reading and Writing with the FileStream Class ................. 53
BufferedStream Class ....................................... 57
MemoryStream Class ....................................... 57 NetworkStream Class ....................................... 58
CryptoStream Class ......................................... 61 Stream Manipulation ............................................. 64
Encoding String Data ........................................ 64
Binary Files ................................................ 67
TextReader ................................................ 70 TextWriter ................................................. 73
Serialization .................................................... 75 Serializing into XML Format .................................. 75 Serializing with Formatter Objects ............................ 78
Summary ...................................................... 83
CHAPTER 3 Network Programming in .NET ............................. 85
System.Net Classes Overview ..................................... 85
Name Lookup .............................................. 85
IP Addresses ............................................... 86 Authentication and Authorization ............................. 86 Requests and Responses .................................... 87
Connection Management .................................... 87
Cookies ................................................... 88
Proxy Server ............................................... 89
Sockets ................................................... 89 Working with URis ............................................... 89
Uri Class .................................................. 91
Properties of the Uri Class ................................... 92 Modifying URis with the UriBuilder Class ....................... 93
Absolute and Relative URis ................................... 94
IP Addresses .................................................... 95 Predefined Addresses ....................................... 96 Host or Network Byte Order .................................. 96
C C TfN"TS vii
Dns Class ...................................................... 97
Resolving a Name to an IP Address ........................... 97 How Is an IP Address Resolved? .............................. 99 Resolving the IP Address Asynchronously ..................... 1 oo
Requests and Responses ........................................ 1 02
WebRequest and WebResponse ............................. 1 02
Pluggable Protocols ........................................ 105
FileWebRequest and FileWebResponse ....................... 1 06
Connection Pooling ........................................ 109
Using a Web Proxy .............................................. 109
Web Proxy Class ........................................... 11 o Default Web Proxy ......................................... 111 Changing the Web Proxy for Specific Requests ................ 111
Authentication ................................................. 112
Permissions ............................................ 112 DnsPermission ............................................ 113
WebPermission ............................................ 113
SocketPermission ......................................... 113
Using Permission Attributes ................................. 113 Configuring Permissions .................................... 116
Summary ..................................................... 119
CHAPTER 4 Socket Programming in .NET .............................. 121
An Overview of Sockets ......................................... 121 SocketTypes .............................................. 122
Sockets and Ports ......................................... 123 Working with Sockets in .NET .................................... 124
Creating a TCP Stream Socket Application .................... 126 Managing Exceptions with System.Net.Sockets ............... 135
Setting and Retrieving Socket Options ........................ 137
Asynchronous Programming ..................................... 140
Creating an Asynchronous Client Application .................. 141
Creating an Asynchronous Server Application ................. 150
Socket Permissions ............................................. 154
Using Imperative Security ................................... 155
Using Declarative Security .................................. 159
Summary ..................................................... 161
viii CONTENTS
IEHAPTER 5 Raw Socket Programming ................................ 163
The ICMP Protocol. ............................................. 163
ICMP Packet Format ....................................... 164
ICMP PacketTypes ......................................... 165
Using Raw Sockets ........................................ 165
Creating an ICMP Class-Formatting ICMP Packets ............ 168
Using ICMP to Create a Tracing Application ................... 176
SNMP ......................................................... 179
Impending SNMP .......................................... 179
SNMP Commands ......................................... 180
Community Names ........................................ 180
Common Management Information Base (MIB) ................ 181
SNMP Packets ............................................ 181
SMTP Class ............................................... 182
Summary ..................................................... 187
IEIHAPTER 6 1Pv6 ......................................................... 189
The Need for a New Protocol ..................................... 189
Features of 1Pv6 ................................................ 190
The 1Pv6 Header ........................................... 191
1Pv6 Addressing ........................................... 192
Installing 1Pv6 on Windows Server 2003 ........................... 195
Installing 1Pv6 with the netsh Command ...................... 195 Installing 1Pv6 through Local Area Connection Properties ....... 196
Verifying 1Pv6 Configuration ................................. 197
.NET Support for 1Pv6 ........................................... 197
Enabling 1Pv6 in Machine.config ............................. 198
Reviewing IPAddress Class Support for 1Pv6 ................... 198
Creating an 1Pv6-Based Client/Server Application .............. 203
Using the 1Pv6Multicast0ption Class ......................... 207
Summary ..................................................... 211
CHAPTER 7 TCP .......................................................... 213
An Overview ofTCP ............................................. 213
Encapsulation ............................................. 213
TCP Headers .............................................. 214
TCP Connections .......................................... 215
TCP Operations ............................................ 216
cornf~ns lx
.NET Support for TCP ........................................... 218
The TcpCiient Class ........................................ 218
Building a Simple E-mail Client Application ................... 223
Creating an FTP Client ..................................... 229
The Tcplistener Class ...................................... 245
Building a Multithreaded Client/Server Application ............. 247
.NET Remoting ................................................. 252
How Remoting Works ...................................... 253
Building a Simple Remoting Application ...................... 255
Creating a Client-Activated Remote Object .................... 260
Summary ..................................................... 261
CHAPTER 8 UOP ......................................................... 263
An Overview of UDP ............................................ 263
UDP Datagrams ........................................... 264
UDP Ports ................................................ 264
How UDP Works ........................................... 265
Differences Between TCP and UDP ........................... 266
.NET Support for UDP ........................................... 269
The UdpCiient Class ........................................ 269
Creating a Chat Application Using UDP ....................... 281
Building a UDP File Transfer Application ...................... 285
Coding the File Server ...................................... 285 Coding the File Receiver .................................... 288
Broadcasting .............................................. 291
Higher-Level UDP-Based Protocols ............................... 292
Summary ..................................................... 293
CHAPTER 9 Multicast Sockets .......................................... 295
Unicasts, Broadcasts, and Multicasts ............................. 295
Unicast Addresses ......................................... 296
Broadcast Addresses ....................................... 296
Multicast Addresses ....................................... 296
Application Models with Multicasting ............................. 297
Many-to-Many Applications ................................. 297
One-to-Many Applications .................................. 298
Architecture of Multicast Sockets ................................. 298
IGMP ..................................................... 299
Multicast Address Allocation ................................ 301
x CONTENTS
Routing ................................................... 303
Scoping .................................................. 305
Routing Protocols .......................................... 305
Scalability ................................................ 306
Reliability ................................................. 306
Security .................................................. 306
Using Multicast Sockets with .NET ................................ 307
Multicast Sender Applications ............................... 307
Multicast Receiver Applications .............................. 308
Creating a Chat Application ...................................... 309
Setting Up the User Interface ................................ 309
Creating the Configuration File .............................. 311
Joining the Multicast Group ................................. 313
Receiving Multicast Messages .............................. 314
Sending Multicast Messages ................................ 315
Dropping the Multicast Membership ......................... 316
Starting the Chat Application ................................ 316
Creating a Picture Show Application .............................. 317
Creating a Picture Protocol .................................. 318
Building the Picture Show Server ............................ 324
Creating the Picture Show Client ............................ 335 Starting the Picture Show ................................... 341
Summary ..................................................... 343
CHAPTER 1 0 HTTP ........................................................ 345
An Overview of HTIP ........................................... 345
HTIP Headers ............................................. 347
HTIP Requests ............................................ 348
HTIP Responses .......................................... 351
Using HTIP with .NET ........................................... 352
The HttpWebRequest and HttpWebResponse Classes ........... 352
Posting Data .............................................. 357
HTIP Chunking ............................................ 358
HTIP Pipelining ........................................... 359
HTIP Keep-Alive Connections ............................... 360
HTIP Connection Management .............................. 361
The WebCiient Class ....................................... 362
Authentication ............................................ 368
Proxy Support ............................................. 370
ICONTt~n xi
Reading and Writing Cookies ..................................... 371 Writing Cookies on the Client. ............................... 371 Reading Cookies on the Client. .............................. 373 Maintaining State with Cookies .............................. 374
Creating an HTIP Server with ASP. NET Support .................... 375 Storing the Server Configuration Information .................. 376 Coding the Basic Server .................................... 377 Hosting ASP. NET Applications Outside liS ..................... 385 Testing the Server ......................................... 386
Building an HTIP Remoting Application ........................... 387 Registering the HTIP Channel ............................... 388 Defining the Remote Class .................................. 388 Creating the Remote Server Application ...................... 389 Creating the Remote Client Application ....................... 390
Summary ..................................................... 391
CHAPTER 11 E-mail Protocols ........................................... 393
How E-mail Works .............................................. 393 Sending E-mail ................................................ 395
SMTP Sessions ............................................ 395 SMTP Reply Codes ......................................... 398
E-mail Message Structure ....................................... 399 Received Headers ......................................... 400 E-mail Attachments (MIME) ................................. 402
Retrieving Client/Server E-mail ................................... 404 POP3 .................................................... 405
IMAP ..................................................... 407 .NET Support for E-Mail Exchange ................................ 409
The System.Web.Mail Namespace ........................... 409 Constructing a MaiiMessage Object. ......................... 410 Adding an Attachment. ..................................... 411 Sending an E-mail Message ................................ 412
Creating an SMTP Mail Application ............................... 412 Creating a POP3 Application ..................................... 414
Creating a POP3 C# Class .................................. 414 Using the POP3 Class in an Application ....................... 420
Building an NNTP Application .................................... 422 Creating an NNTP Class in C# ............................... 423 Using the NNTP Class in an Application ....................... 428
Summary ..................................................... 429
xU CONTENTS
IEHAPTER 12 Cryptography in .NET ...................................... 431
History of Cryptography ......................................... 431
What Is Cryptography? .......................................... 432
Why Use Cryptography? ......................................... 434
Concepts of Cryptography .................................. 434
Cryptographic Algorithms ........................................ 435
Symmetric Algorithms ...................................... 436
Asymmetric Algorithms ..................................... 437
Message Digest Algorithms ................................. 439
Digital Signatures .......................................... 440
Cryptography Terminology ....................................... 441
Block Ciphers and Stream Ciphers ........................... 441
Padding .................................................. 441
Modes ................................................... 443
The System.Security.Cryptography Namespace .................... 444
Cryptography Class Hierarchy ............................... 444
Hashing with .NET .............................................. 445
The HashAigorithm Class ................................... 446
Symmetric Transformation with .NET ............................. 453
The SymmetricAigorithm Class .............................. 453 Using Other Symmetric Algorithms ........................... 458
Asymmetric Transformation with .NET ............................ 459
The AsymmetricAigorithm Class ............................. 459
Using the RSA Algorithm .................................... 460
Loading the Public and Private Keys ......................... 463
Reading an X509 Certificate ..................................... 466
Cryptography and Network Programming .......................... 468
Summary ..................................................... 474
~ CHAPTER 13 Authentication Protocols .................................. 475
Authentication and Authorization ................................. 475
NTLM ......................................................... 476
How Challenge/Response Authentication Works ............... 476
NTLM Development ........................................ 476
Kerberos ...................................................... 480
How Key-Based Authentication Works ........................ 480
The Kerberos Authentication Process ......................... 483
Windows 2000 Implementation of Kerberos ................... 486
CONTENTS xiii
Windows Authentication ......................................... 487
An Overview of Windows Authentication Methods .............. 487
Windows 2000 Security Support Provider Interface (SSPI) ....... 488
.NET Security .................................................. 493
The .NET Code Access Security Policy ........................ 493
.NET Resource Security .................................... 494
.NET Role-Based Security ................................... 498
Client Authentication Handling ............................... 498
Impersonation ............................................. 499
Summary ..................................................... 500
.NDEX ....................................................................... 501
About the Technical Reviewer
CHRISTIAN NAGEL has about 20 years of experience as developer and software architect. He is working as an independent trainer and consultant offering courses, seminars, and coaching, based on Microsoft .NET technologies.
Christian started his computing career with PDP 11 and VAX/VMS platforms, covering a variety oflanguages and platforms. Since 2000 he has been working with .NET and C# developing and architecting distributed solutions. Certified as a Microsoft Certified Trainer (MCT), Microsoft Certified Solution Developer (MCSD), Microsoft Certified System Engineer (MCSE), and MSF (Microsoft Solutions Framework) Practitioner, he furthermore loves writing and enjoys a good reputation as an author of several .NET books, such as Professional C#, Professional.NET Network Programming, C# Web Services, and Enterprise Services with the .NET Framework. In his role as Microsoft Regional Director and MVP for Visual C#, he speaks at international conferences. Christian is also known as Regional Manager of INETA Europe (lnternational.NET User Group Association), and since 2004 he has become an associate of Thinktecture, a team of experts who offer consultancy and training about .NET technologies.
You can contact Christian via his web site at http: I IWVM. christiannagel. com.
~.JIT MUNGALE has extensive experience with Microsoft technologies and has worked with almost all languages and technologies. He also has experience with IBM products, including IBM WebSphere and MQ. He is author of a couple other books and published articles on Microsoft .NET.
ANDREW KROWClYK is a software architect and MCSD.NET working in the Chicago area. He currently works heavily with cutting edge .NET technologies. Andrew's area of expertise includes Enterprise applications and theoretical computer science. He also works as an adjunct faculty member at Elmhurst College. He can be reached at KROWCZYK@I -NETWAY. COM.
VI NOD KUMAR is a Microsoft MVP from Chennai, India. He has authored many books on Microsoft technologies, such as MOBILE APPLICATION DEVELOPMENT USING • NET and Planning, Implementing, and Maintaining a Windows Server 2003 Active Directory Infrastructure. He also owns a site named .NET Force (HTTP: I IWWW. DOTNETFORCE. COM). The site provides the latest information and publishes original articles on .NET technology. He can be reached at [email protected].
S. SRINIVASA SIVAKUMAR works as a solution architect for Microsoft Corporation India and is an author and speaker specializing in Web and mobile solutions using .NET technologies.
XV
About the Technical Reviewer
ALEXANDRU SERBAN is a software engineer for MMC Softlabs, building enterprise management information systems for large, geographically distributed companies.
Alexandru started his addiction to computers when he first saw video game machines. He started his programming career at the age of 9, when he bought his first Z80 processor-based computer and started learning BASIC. He then moved toward languages like Visual Basic, C, and C++. He graduated in computer science and automatic systems. Now, he specializes in network communications, and he is very enthusiastic about C# and the .NET Framework, which he strongly believes is set to revolutionize programming.
In his free time, he likes to drive and travel, in the summer to the sea, and in the winter to the mountains, where he hits the slopes with a snowboard.
xvii
Introduction
Network programming is one of the core tasks of enterprise-level development-the need for disparate computers to communicate efficiently and securely, whether within the same building, or across the world, remains fundamental to the success of many systems. With the .NET 1.1 Framework comes a new set of classes for tackling networking tasks.
These classes make common network programming tasks very easy and straightforward, as they provide a layered, extensible, and managed implementation of Internet services that can be integrated into your applications.
After reading this book, you will be a confident .NET 1.1 network programmer who understands all the underlying protocols. The current set of protocols supported by .NET 1.1 classes is limited to the transport-level protocols TCP and UDP, and the application-level protocols HTTP and SMTP. In this book, we provide not only full coverage of these classes, but also examples of implementing application-level protocols in .NET-so this book will be vital reading for anyone who needs to use a protocol that isn't currently supported by .NET 1.1, as well as for anyone who wants to get to grips with the predefmed protocols.
Who Is This Book For? You do not need any prior knowledge of network programming to read this book, because you will learn the basic and then more advanced networking concepts as you follow each chapter. You may already be familiar with network programming from another environment, of coursein which case, you will still find the pace strong enough for the book to prove valuable.
We're going to assume you have a working knowledge of C# to read the examples and code solutions we provide. Sometimes we will also present techniques that are specifically suitable to the C# language.
What Is in This Book? We begin this book by introducing you to some of the basic concepts and protocols of networking in Chapter 1. Whatever your requirements from network programming-whether you plan to develop server applications running as Windows Services offering data for clients using a custom protocol, whether you want to write client applications that request data from web servers, or whether you want to create multicasting applications or applications using mailing functionality-this chapter is your first port of call.
We begin Chapter 1 with a look at the physical network, and the hardware used in network communication. We will start with an introduction to the types of networks in use today, like local area networks (LANs), wide area networks (WANs), and metropolitan area networks (MANs); and network architectures and network devices, such as network interface cards (NICs), routers, hubs, and bridges. Then, we'll take a look at the OSI seven-layer model, and how the TCP liP protocol suite fits into the OSI layers. After that, we introduce you to the xlx
xx IIINTRODUCTION
various network, Internet, and e-mail protocols, such as IP, TCP, UDP, ICMP, IGMP, FTP, HTTP, SMTP, POP3, IMAP, and NNTP. The end of this chapter explains domain names, firewalls, web proxies, and XML web services.
Chapter 2 provides you with a background for working with streams. A stream is an abstract representation of a sequence of bytes such as a file, an I/0 device, or a TCP /IP socket. Through this abstraction, different devices can be accessed with the same process, and similar code can be used to read data from a file input stream as can be used to read data from a network input stream, for example. In this way, the programmer's need to worry about the actual physical mechanism of the device is removed. We take a look at streams in .NET 1.1-the STREAM base class for all other stream types, and work with the concrete FILESTREAM, BUFFEREDSTREAM, MEMORYSTREAM, NETWORKSTREAM, and CRYPTOSTREAM classes and stream manipulation. We also show you how to read from and write to binary and text files, and serialize objects into XML and binary format.
Chapter 3 starts to get you to grips with network programming in .NET 1.1, beginning I
with classes from the SYSTEM. NET namespace. We kick off with a discussion of these classes-and you'll see later on how they play a fundamental role in all the following chapters of this book. Specifically, we'll see how to work with URis, IP addresses, and DNS lookups. We see how to handle requests and responses through the WEBREQUEST and WEBRESPONSE classes, and begin looking at authentication, authorization, and the permissions relevant to network programming.
Chapter 4 is about socket programming, and we explain to you the low-level programming that is required to perform network-related tasks. A socket is one end of a two-way communication link between two programs running on a network. We'll look at the socket support in .NET-the SYSTEM. NET. SOCKETS. SOCKET class, building a port scanner application, and creating both synchronous and asynchronous client-server applications.
Chapter 5 deals with the details of raw socket programming, the base for building custom network protocols. The first part of this chapter covers the basic implementation of the Internet Control Message Protocol (ICMP) and the second part the Simple Network Management Protocol (SNMP). As ICMP deals with Internet control messages, we will build two of the most used utilities in network diagnostic scenarios: PING and TRACEROUTE. Then, we will show an implementation of the SNMP protocol, used for remote network device management.
Chapter 6 is about a new addition in .NET Framework 1.1: the support for the IPv6 protocol. IPv6 is short for Internet Protocol Version 6. IPv6 is the "next generation'' protocol designed by the Internet Engineering Task Force (IETF) to replace the current version Internet Protocol, IP Version 4 (IPv4). IPv6 fixes a number of problems in IPv4, such as the limited number of available IPv4 addresses. It also adds many improvements to IPv4 in areas such as routing and network auto-configuration. We will discuss the .NET and Windows operating system support for IPv6, showing how to install and configure this protocol. Then we will build an IPv6-based client-server application and a simple multicast application showing the basics of multicast network communication.
In Chapter 7, we begin a tour of the higher-level network classes in the .NET Framework, commencing with those for dealing with the Transmission Control Protocol (TCP). We start with a general introduction to TCP, and its architecture and data structures, before moving on to explore the TCPCLIENT and TCPLISTENER classes for working with TCP. You'll build clientserver applications using the TCPCLIENT and TCPLISTENER classes, and then write a fully functional e-mail client to see the power ofTCPCLIENT. You'll also create a multithreaded echo server, with the support of the .NET multithreading classes. We end this chapter for you
IIINTRODUCTION xxi
with a quick look at the .NET Remoting Framework, and particularly the TCPCHANNEL transport channel provided with the .NET 1.1 Framework.
Chapter 8 is about the UDPCLIENT class, through which we implement the User Datagram Protocol (UDP). You'll learn about the fundamentals of the UDP protocol, and then see how to use the UDPCLIENT class. While TCP is a more reliable protocol than UDP, it also adds a lot of overhead. Accordingly, UDP is faster, and is well suited for multimedia transmissions such as video streams-where the precise order that packets arrive in may not be critical. In this chapter, we also discuss with you the higher-level UDP-based protocols.
Chapter 9 is about multicasting. This is the technology that made possible the transmission of a live Rolling Stones concert in 1994 over the Internet; it allows us to watch astronauts in space, or to hold meetings over the Internet, to name but a few benefits. With multicasting, a server only has to send messages once, and they will be distributed to a whole group of clients. We therefore begin Chapter 9 by comparing unicasts, broadcasts, and multicasts. You'll study the architecture of multicasting, and learn how to implement multicast sockets in .NET 1.1. You create two Windows applications in this chapter using multicasting featuresone application makes it possible to chat with multiple systems, where everyone is both a sender and a receiver. The second application-in the form of a picture show-demonstrates for you how large data packets can be sent to multiple clients without using a large percentage of the network bandwidth.
Chapter 10 covers the HTTP protocol and its robust implementation exposed by .NET. The HTTP protocol's importance as an application protocol is significant, since a large share of web traffic today uses this protocol. In Chapter 10, we therefore begin with an overview of the HTTP protocol-the HTTP headers, and the format of HTTP requests and responses. You'll take a deep look at the classes in .NET for working with HTTP, and see how to read and write cookies. You'll then see how to create an HTTP server with ASP. NET support, before continuing your study of .NET Remoting and the HTTP transport channel. You'll be well set in this area after reading this chapter.
We get to e-mail in Chapter 11. In this chapter, we begin with a high-level overview of the various e-mail protocols and how they are accessed and used in a .NET 1.1 environment. We'll show you the fundamentals of the SMTP, POP3, IMAP, and NNTP protocols, and see how these protocols work together to send and receive e-mail messages over the Internet. We'll also take a look at sending e-mails with the .NET Framework's classes for sending e-mails via SMTP, as well as developing some grassroots protocol implementation classes for POP3 and SMTP.
In Chapter 12, we discuss the topic of securing network communications. The SYSTEM. SECURITY. CRYPTOGRAPHY namespace of the .NET Framework provides programmatic access to the variety of cryptographic services that we can incorporate into our applications to encrypt and decrypt data, ensure data integrity, and handle digital signatures and certificates. In this chapter, we'll therefore explore with you this namespace, but also provide you with an introduction to cryptography and all of its key concepts. This is a topic you can take much further, of course, but we open that door for you in this chapter. We'll also take a look at securing a particular chat application that we created earlier in the book.
We close the book with Chapter 13, where we take a look at authentication protocols. Authentication has become a major issue for any application developer who expects code to run across a network, or across the Internet. Making sure that users are who they say they are, and verifying machine identities on demand, is all part of an application's security module. In this final chapter, you'll see what the authentication protocols involved in Microsoft's networking schemes are, how they work, and how they apply to the various versions ofWindows.
xxii IIINTRODUCTION
We will discuss protocols such as NTLM, Kerberos, and various types ofWmdows authentication methods such as Credentials Management, GINA, LSA, smartcard authentication, and Wmlogon. At the end of the chapter, we'll show you the .NET security architecture, and provide you with an explicit implementation of the .NET Resource Security.
What You Need to Use This Book To run the code solutions and examples in this book, you need to have a machine with the .NET 1.1 Framework installed. This means that you'll need to be running either a type ofWmdows server (Wmdows 2000 Server or above) or a Wmdows workstation type (Wmdows 2000 Professional or Wmdows XP). We also recommend that you use Visual Studio .NET 2003 with this book, but you can also build the sample applications using the .NET Framework l.l SDK.