Vous êtes sur la page 1sur 13

Contents at a Glance

Chapter 2:

IP Programming Basics

Chapter 3:

C# Network Programming Classes

Chapter 4:

DNS and C#

MA

3
41
87
125

TE

Network Layer Programing

Connection-Oriented Sockets

167

Chapter 6:

Connectionless Sockets

209

Chapter 7:

Using The C# Sockets Helper Classes

249

Chapter 8:

Asynchronous Sockets

291

Chapter 9:

Using Threads

333

IP Multicasting

375

GH

Chapter 5:

CO

Chapter 10:

Part III

RI

The C# Language

TE

Chapter 1:

xix

RI

Part II

Network Programming Basics

PY

Part I

AL

Introduction

Application Layer Programming Examples


Chapter 11:

ICMP

411

Chapter 12:

SNMP

441

Chapter 13:

SMTP

477

Chapter 14:

HTTP

511

Chapter 15:

Active Directory

535

Chapter 16:

Remoting

563

Chapter 17:

Security

593

Index

623

Contents

Introduction

Part I
Chapter 1

xix

Network Programming Basics

The C# Language

Basics of .NET
Common Language Runtime (CLR)
MSIL Code
Installing a C# Development Environment
C# Development Options
Downloading the .NET Framework SDK
Installing the .NET Framework SDK
The C# Runtime Environment
Downloading and Installing the C# Runtime Package
Developing with the C# Runtime
C# Programming Basics
Creating C# Programs
Compiling and Running C# Programs
Using Multiple Source Files
Debugging C# Programs
Debugging MSIL Code
C# Features
C# Namespaces
Using Strings in C# Programs
C# Streams
C# Exception Programming
Summary

4
4
5
6
7
8
9
10
11
11
12
12
15
16
17
22
23
24
28
33
36
39

Contents

Chapter 2

Chapter 3

Chapter 4

IP Programming Basics

41

Watching Network Traffic


Installing the WinPcap Programs
The WinDump Program
The Analyzer Program
Analyzing Network Packets
The Ethernet Layer
The IP Layer
The TCP Layer
The UDP Layer
Programming with TCP and UDP
TCP Programming Features
UDP Programming Features
Finding IP Address Information
Using ipconfig
Using the Registry
Using WMI
Using DNS
Summary

42
43
44
48
51
51
56
61
68
69
70
71
72
72
74
80
83
84

C# Network Programming Classes

87

A Primer on Socket Programming


Socket Programming in Windows
C# Socket Programming
IP Addresses in C#
Using C# Sockets
C# Socket Exceptions
C# Socket Helper Classes
TcpClient
TcpListener
UdpClient
Summary

88
98
103
103
108
119
120
120
122
123
124

DNS and C#

125

The Domain Name System (DNS)


DNS Structure
Finding a Hostname in DNS

127
127
130

Contents

Part II
Chapter 5

Chapter 6

xi

The DNS Database


A Sample DNS Database
Windows DNS Client Information
DNS Configuration
Using C# to Investigate the DNS Configuration
Resolving Hostnames with nslookup
DNS Classes in C#
Synchronous Methods
Asynchronous Methods
Summary

131
136
138
138
141
144
153
153
159
164

Network Layer Programing

165

Connection-Oriented Sockets

167

A Simple TCP Server


Creating the Server
Testing the Server
Watching the Server
A Simple TCP Client
Creating the Client
Testing the Client
When TCP Goes Bad
Problems with Data Buffers
Problems with TCP Messages
Solving the TCP Message Problem
Using C# Streams with TCP
The NetworkStream Class
The StreamReader and StreamWriter Classes
Summary

168
168
172
172
173
174
176
177
177
180
184
198
198
202
207

Connectionless Sockets

209

A Simple UDP Application


The UDP Server
A UDP Client
Testing the Client and Server Programs
Using Connect() in a UDP Client Example

210
211
215
217
219

xii

Contents

Chapter 7

Chapter 8

Distinguishing UDP Messages


When UDP Goes Bad
Preventing Lost Data
Preventing Lost Packets
A Complete UDP Application
Catching Multiple Exceptions by Monitoring Error Codes
The Complete Client Program
Summary

220
223
223
228
242
242
245
247

Using The C# Sockets Helper Classes

249

The TcpClient Class


The TcpClient Class Constructors
The TcpClient Class Methods
Creating a Simple Client Program
Testing the Program
The TcpListener Class
The TcpListener Class Constructors
The TcpListener Class Methods
A Simple Server Program
Incorporating the StreamReader and StreamWriter Classes
The UdpClient Class
The UdpClient Class Constructors
The UdpClient Class Methods
Using the UdpClient Class in Programs
A Simple UdpClient Server Program
A Simple UdpClient Client Program
Testing the Sample Programs
Moving Data across the Network
Moving Binary Data
Communicating with Other Host Types
Moving Complex Objects
Summary

250
250
251
252
254
255
255
256
257
258
259
259
260
260
262
263
264
265
265
272
280
288

Asynchronous Sockets

291

Windows Event Programming


Using Events and Delegates

292
293

Contents

Chapter 9

xiii

The AsyncCallback Class


Using Asynchronous Sockets
Establishing the Connection
Sending and Receiving Data
Sample Programs Using Asynchronous Sockets
The Client Program
The Server Program
Using Non-blocking Socket Methods
The Poll() Method
The Select() Method
Summary

297
298
298
301
304
305
312
319
319
324
331

Using Threads

333

How Applications Run in Windows


Finding Process Information Using C#
Threads
Creating Threads in a Program
The Thread Class
Using the Thread Class
Using Threads in a Server
Creating a Threaded Server
Testing the Server
Watching the Threads
Using Threads for Sending and Receiving Data
The TcpChat Program
Testing the Chat Program and Watching the Threads
Thread Pools
The ThreadPool Class
A Sample ThreadPool Program
Testing the Program and Watching the Threads
Using Thread Pools in a Server
A ThreadPool Server
Testing the Program and Watching the Threads
Summary

334
335
343
350
350
351
354
354
357
357
358
359
363
364
365
366
367
369
369
371
373

xiv

Contents

Chapter 10

Part III
Chapter 11

IP Multicasting

375

What Is Broadcasting?
Local versus Global Broadcasts
Implementing Broadcasting with C#
Using Broadcast Packets to Advertise a Server
The Advertising Loop
What Is Multicasting?
Multicast Techniques
Sending Multicast Packets through Routers
C# IP Multicast Support
C# Socket Multicasting
C# UdpClient Multicasting
Sample Multicast Application
Testing the Multicast Chat Program
Summary

376
376
377
382
382
390
391
392
393
394
399
402
405
406

Application Layer Programming Examples

409

ICMP

411

The ICMP Protocol


ICMP Packet Format
ICMP Packet Types
Using Raw Sockets
Raw Sockets Format
Sending Raw Packets
Receiving Raw Packets
Creating an ICMP Class
The ICMP Class Constructors
The ICMP Packet Creator
The ICMP Checksum Method
Putting It All Together
A Simple Ping Program
Testing SimplePing
An Advanced Ping Program
Testing AdvPing

412
412
413
415
415
416
417
417
417
420
420
422
423
425
426
431

Contents

Chapter 12

Chapter 13

xv

The TraceRoute.cs Program


Testing TraceRoute.cs
The FindMask Program
The Subnet Request Packet
Testing FindMask.cs
Summary

432
434
435
435
437
438

SNMP

441

Understanding SNMP
SNMP Commands
Community Names
Common Management Information Base
Working with SNMP Packets
SNMP Packet Format
SNMP Packet Layout
SNMP Communication
Creating a Simple SNMP Class
The SNMP Class Program
Walking through the Class
The SimpleSNMP Program
Testing the Program
Watching the Packets
Using Vendor MIBs
The Cisco CPU MIB
The CiscoRouter Program
Using GetNextRequest Queries
Extracting the Next MIB
The getnextMIB() Method
The MAC Address Program
Testing the Program
Summary

442
443
444
445
448
448
450
452
452
453
455
457
461
462
463
463
466
469
469
470
471
473
474

SMTP

477

E-mail Basics
The MTA Process

478
478

xvi

Contents

Chapter 14

The MDA Process


The MUA Process
SMTP and Windows
Collaboration Data Objects (CDO)
SMTP Mail Service
The SmtpMail Class
Class Methods and Properties
Using the SmtpMail Class
Using Expanded Mail Message Formats
The RFC2822 Mail Format
The MailMessage Class Properties
Using the MailMessage Class
Mail Attachments
uuencode
MIME
The MailAttachment Class
A POP3 Client
The POP3 Protocol
Writing a POP3 Client
Summary

480
481
483
483
484
485
486
487
488
488
491
493
494
495
495
499
501
501
504
510

HTTP

511

The WebClient Class


Downloading Web Data
Viewing HTTP Headers
Uploading Web Data
Using Credentials
Advanced Web Classes
The HttpWebRequest Class
The HttpWebResponse Class
Advanced Web Client Example
Web Services
Creating the Web Service Server
Testing the Web Service
Creating the Web Service Proxy
Creating a C# Web Service Client
Summary

512
512
515
516
519
521
522
523
525
528
529
531
532
533
534

Contents

Chapter 15

Chapter 16

xvii

Active Directory

535

Network Directory Basics


The LDAP System
LDAP Objects and Attributes
Working with Active Directory
Parts of an Active Directory
Connecting to an Active Directory Server
Using C# to Access a Network Directory
Modifying Directory Data
Working with Object Properties
Working with Objects
Searching the Network Directory
Step 1: Defining the Search Properties
Step 2: Retrieving the Search Results
Step 3: Extracting the Search Results
Performing a Search
Advanced Search Features
Summary

536
536
537
539
539
543
543
546
546
550
556
556
557
558
558
560
561

Remoting

563

Moving Data, Revisited


Using a Serialization Class
Problems with Serialization
An Overview of Remoting
The Remote Class
The Remoting Server
The Communication Channel
The Proxy Class
The Client Program
Using Remoting
Creating the Remote Class Proxy
Creating the Server Program
Creating the Client Program
Creating a Proxy Class Using soapsuds
Viewing the Remote Class Interfaces
The soapsuds Program
Summary

564
564
571
574
575
576
577
577
577
578
578
579
583
585
585
586
590

xviii

Contents

Chapter 17

Index

Security

593

Application Security: Whats Involved?


Security Policies
Security Groups
Security Permissions
Security Tools
Socket Permissions
Implementing Declarative Security
Using Declarative Security
Protecting Network Data
Data Encryption
Using Data Encryption
Network Data Encryption
Summary

594
594
595
596
597
603
604
606
610
610
612
615
621

623

Vous aimerez peut-être aussi