2003 sybex c sharp network programming

1K 101 0
2003   sybex   c sharp network programming

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

C# Network Programming by Richard Blum Sybex © 2003 (647 pages) ISBN:0782141765 This book helps newcomers get started with a look at the basics of network programming as they relate to C#, including the language’s network classes, the Winsock interface, and DNS resolution Table of Contents C# Network Programming Introduction Part I - Network Programming Basics Chapter 1 Chapter 2 Chapter 3 Chapter 4 - The C# Language - IP Programming Basics - C# Network Programming Classes - DNS and C# Part II - Network Layer Programing Chapter 5 - Connection-Oriented Sockets Chapter 6 - Connectionless Sockets Chapter 7 - Using The C# Sockets Helper Classes Chapter 8 - Asynchronous Sockets Chapter 9 - Using Threads Chapter 10 - IP Multicasting Part III - Application Layer Programming Examples Chapter 11 - ICMP Chapter 12 - SNMP Chapter 13 - SMTP Chapter 14 - HTTP Chapter 15 - Active Directory Chapter 16 - Remoting Chapter 17 - Security Index List of Figures List of Tables List of Listings List of Sidebars Back Cover On its own, C# simplifies network programming Combine it with the precise instruction found in C# Network Programming, and you’ll find that building network applications is easier and quicker than ever This book helps newcomers get started with a look at the basics of network programming as they relate to C#, including the language’s network classes, the Winsock interface, and DNS resolution Spend as much time here as you need, then dig into the core topics of the network layer You’ll learn to make sockets connections via TCP, and “connectionless” connections via UDP You’ll also discover just how much help C# gives you with some of your toughest chores, such as asynchronous socket programming, multithreading, and multicasting Network-layer techniques are just a means to an end, of course, and so this book keeps going, providing a series of detailed application-layer programming examples that show you how to work with real protocols and real network environments to build and implement a variety of applications Use SNMP to manage network devices, SMTP to communicate with remote mail servers, and HTTP to Web-enable your applications And use classes native to C# to query and modify Active Directory entries Rounding it all out is plenty of advanced coverage to push your C# network programming skills to the limit For example, you’ll learn two ways to share application methods across the network: using Web services and remoting You’ll also master the security features intrinsic to C# and NET—features that stand to benefit all of your programming projects About the Author Richard Blum has spent 14 years as a network and system administrator for the US Department of Defense, supporting a large network of workstations and servers He holds a BS in Electrical Engineering and an MS in Management Information Systems, both from Purdue University C# Network Programming Richard Blum Associate Publisher: Joel Fugazzotto Acquisitions Editor: Denise S Lincoln Developmental Editor: Carol Henry Editor: Sally Engelfried Production Editor: Erica Yee Technical Editor: Dan Frumin Graphic Illustrator: Jeff Wilson, Happenstance Type-O-Rama Electronic Publishing Specialists: Scott Benoit, Judy Fung Proofreaders: Emily Hsuan, Dave Nash, Laurie O’Connell, Yariv Rabinovitch, Nancy Riddiough Indexer: Ted Laux Cover Designer: Carol Gorska, Gorska Design Cover Photographer: Carlos Navajas, The Image Bank Copyright © 2003 SYBEX Inc., 1151 Marina Village Parkway, Alameda, CA 94501 World rights reserved No part of this publication may be stored in a retrieval system, transmitted, or reproduced in any way, including but not limited to photocopy, photograph, magnetic, or other record, without the prior agreement and written permission of the publisher Library of Congress Card Number: 2002111958 ISBN: 0-7821-4176-5 SYBEX and the SYBEX logo are either registered trademarks or trademarks of SYBEX Inc in the United States and/or other countries Screen reproductions produced with FullShot 99 FullShot 99 © 19911999 Inbit Incorporated All rights reserved.FullShot is a trademark of Inbit Incorporated Internet screen shot(s) using Microsoft Internet Explorer Version 6 reprinted by permission from Microsoft Corporation TRADEMARKS: SYBEX has attempted throughout this book to distinguish proprietary trademarks from descriptive terms by following the capitalization style used by the manufacturer The author and publisher have made their best efforts to prepare this book, and the content is based upon final release software whenever possible Portions of the manuscript may be based upon pre-release versions supplied by software manufacturer(s) The author and the publisher make no representation or warranties of any kind with regard to the completeness or accuracy of the contents herein and accept no liability of any kind including but not limited to performance, merchantability, fitness for any particular purpose, or any losses or damages of any kind caused or alleged to be caused directly or indirectly from this book Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 Software License Agreement: Terms and Conditions The media and/or any online materials accompanying this book that are available now or in the future contain programs and/or text files (the “Software”) to be used in connection with the book SYBEX hereby grants to you a license to use the Software, subject to the terms that follow Your purchase, acceptance, or use of the Software will constitute your acceptance of such terms The Software compilation is the property of SYBEX unless otherwise indicated and is protected by copyright to SYBEX or other copyright owner(s) as indicated in the media files (the “Owner(s)”) You are hereby granted a single-user license to use the Software for your personal, noncommercial use only You may not reproduce, sell, distribute, publish, circulate, or commercially exploit the Software, or any portion thereof, without the written consent of SYBEX and the specific copyright owner(s) of any component software included on this media In the event that the Software or components include specific license requirements or end-user agreements, statements of condition, disclaimers, limitations or warranties (“End-User License”), those EndUser Licenses supersede the terms and conditions herein as to that particular Software component Your purchase, acceptance, or use of the Software will constitute your acceptance of such End-User Licenses By purchase, use or acceptance of the Software you further agree to comply with all export laws and regulations of the United States as such laws and regulations may exist from time to time Reusable Code in This Book The author(s) created reusable code in this publication expressly for reuse by readers Sybex grants readers limited permission to reuse the code found in this publication, and available for download from our website so long as the author(s) are attributed in any application containing the reusable code and the code itself is never distributed, posted online by electronic transmission, sold, or commercially exploited as a stand-alone product Software Support Components of the supplemental Software and any offers associated with them may be supported by the specific Owner(s) of that material, but they are not supported by SYBEX Information regarding any available support may be obtained from the Owner(s) using the information provided in the appropriate read.me files or listed elsewhere on the media Should the manufacturer(s) or other Owner(s) cease to offer support or decline to honor any offer, SYBEX bears no responsibility This notice concerning support for the Software is provided for your information only SYBEX is not the agent or principal of the Owner(s), and SYBEX is in no way responsible for providing any support for the Software, nor is it liable or responsible for any support provided, or not provided, by the Owner(s) Disclaimer SYBEX makes no warranty or representation, either expressed or implied, with respect to the Software or its contents, quality, performance, merchantability, or fitness for a particular purpose In no event will SYBEX, its distributors, or dealers be liable to you or any other party for direct, indirect, special, incidental, consequential, or other damages arising out of the use of or inability to use the Software or its contents even if advised of the possibility of such damage In the event that the Software includes an online update feature, SYBEX further disclaims any obligation to provide this feature for any specific duration other than the initial posting The exclusion of implied warranties is not permitted by some states Therefore, the above exclusion may not apply to you This warranty provides you with specific legal rights; there may be other rights that you may have that vary from state to state The pricing of the book with the Software by SYBEX reflects the allocation of risk and limitations on liability contained in this agreement of Terms and Conditions Shareware Distribution This Software may contain various programs that are distributed as shareware Copyright laws apply to both shareware and ordinary commercial software, and the copyright Owner(s) retains all rights If you try a shareware program and continue using it, you are expected to register it Individual programs differ on details of trial periods, registration, and payment Please observe the requirements stated in appropriate files Copy Protection The Software in whole or in part may or may not be copy-protected or encrypted However, in all cases, reselling or redistributing these files without authorization is expressly forbidden except as specifically provided for by the Owner(s) therein This book is dedicated to Sister Marie Imelda, C.S.C, who in the late 1970s fought and struggled to teach a bunch of goofy high school kids how to program Thanks, Sister “Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make your paths straight.” Prov 3:5-6 (NIV) Acknowledgments First, all honor, glory, and praise goes to God, who through His Son, all things are possible, and who gives us the gift of eternal life I would like to thank all the great people at Sybex for their help, guidance, and professionalism Thanks to Denise Santoro Lincoln, the Acquisitions Editor, for offering me the opportunity to write this book Also, thanks to Carol Henry, the Developmental Editor, for all her work guiding this book along and helping make my paragraphs make sense Many thanks to Sally Engelfried, the Copy Editor, for turning my poor grammar into perfect sentences, and to Dan Frumin, the Technical Editor, for going above and beyond the call of duty fixing my programs and pointing out my technical blunders Also, thanks to Carole McClendon at Waterside Productions for her help in arranging this book for me Finally, I would like to thank my parents, Mike and Joyce Blum, for their dedication and support, and my wife Barbara and daughters Katie Jane and Jessica for their faith, love, and understanding, especially while I was writing this book The quotation on the bottom of the front cover is taken from the sixty-third chapter of Lao Tzu’s Tao Te Ching, the classic work of Taoist philosophy This particular verse is from the translation by D C Lau (copyright 1963) and communicates the idea that one should confront the difficult while it is still easy and accomplish a great task by a series of small acts It is traditionally held that Lao Tzu lived in the fifth century B.C in China, during the Chou dynasty, but it is unclear whether he was actually a historical figure It is said that he was a teacher of Confucius The concepts embodied in the Tao Te Ching influenced religious thinking in the Far East, including Zen Buddhism in Japan Many in the West, however, have wrongly understood the Tao Te Ching to be primarily a mystical work; in fact, much of the advice in the book is grounded in a practical moral philosophy governing personal conduct Introduction Networks (and network programming) have come a long way over the past 20 years In the early days of network computing (the ’80s), network programming was left to the advanced programmer, who typically built applications using the C programming language in (mostly) Unix environments Now, networks are everywhere, from large corporations to small home users With so many computers connected together via networks, network-aware applications are an accepted necessity Existing applications must incorporate network features to stay competitive in the marketplace, and adding network communication to applications is essential Network programs are used for everything from children’s games to advanced corporate database systems Network programming has always been a key feature of the Microsoft Windows operating system Unfortunately, you’ve had to know advanced C or C++ programming concepts to utilize the network programming features in Windows programs Now, though, the NET Framework languages simplify the task of adding network features to your applications The NET libraries provide many network classes that can integrate network programming As a network administrator, I’ve written many network programs using the C and Java languages for both Windows and Unix platforms Today’s network management and security requirements make it essential to communicate with network devices and track workstations on the network Trying to quickly write clean network code can be difficult when you are working within the structure of the C socket APIs (especially in WinSock), and running Java applications is often a painful experience due to slow processing speeds and poor Windows support The C# language has solved many of my network programming problems by allowing me to quickly prototype and deploy network applications using C# classes Combining the C# Forms library to write the graphical code with the C# Socket library to write the networking code makes creating professional network applications simple With C# network classes, what used to take a day to write often only takes an hour or less Chapter 8: Asynchronous Sockets Listing 8.1: The WindowSample.cs program Listing 8.2: The AsyncTcpClient.cs program Listing 8.3: The AsyncTcpSrvr.cs program Listing 8.4: The TcpPollSrvr.cs program Listing 8.5: The SelectTcpSrvr.cs program Listing 8.6: The SelectTcpClient.cs program Chapter 9: Using Threads Listing 9.1: The GetProc.cs program Listing 9.2: The ListProcs.cs program Listing 9.3: The GetThreads.cs program Listing 9.4: The ListThreads.cs program Listing 9.5: The ThreadSample.cs program Listing 9.6: The ThreadedTcpSrvr.cs program Listing 9.7: The TcpChat.cs program Listing 9.8: The ThreadPoolSample.cs program Listing 9.9: The ThreadPoolTcpSrvr.cs program Chapter 10: IP Multicasting Listing 10.1: The BadBroadcast.cs program Listing 10.2: The Broadcst.cs program Listing 10.3: The RecvBroadcst.cs program Listing 10.4: The Advertise.cs program Listing 10.5: The NewTcpChat.cs program Listing 10.6: The MultiRecv.cs program Listing 10.7: The MultiSend.cs program Listing 10.8: Sample WinDump output from the multicast test Listing 10.9: The NewMultiSend.cs program Listing 10.10: The UdpClientMultiRecv.cs program Listing 10.11: The UdpClientMultiSend.cs program Listing 10.12: The WinDump output from the UdpClient multicast test Listing 10.13: The MulticastChat.cs program Chapter 11: ICMP Listing 11.1: The getChecksum() ICMP method Listing 11.2: The ICMP.cs program Listing 11.3: The SimplePing.cs program Listing 11.4: The AdvPing.cs program Listing 11.5: The TraceRoute.cs program Listing 11.6: The FindMask.cs program Listing 11.7: The WinDump output from the FindMask program Chapter 12: SNMP Listing 12.1: The SNMP.cs program Listing 12.2: The SimpleSNMP.cs program Listing 12.3: The SimpleSNMP program network trace (WinDump) Listing 12.4: Cisco CPU Utilization MIBs Listing 12.5: The CiscoRouter.cs program Listing 12.6: The getnextMIB() method of the SNMP class Listing 12.7: The MacAddress.cs program Listing 12.8: Sample MacAddress program output Chapter 13: SMTP Listing 13.1: The MailTest.cs program Listing 13.2: The FancyMailTest.cs program Listing 13.3: The MailAttachTest.cs program Listing 13.4: The PopCheck.cs program Chapter 14: HTTP Listing 14.1: The DownloadDataTest.cs program Listing 14.2: The DownloadFileTest.cs program Listing 14.3: The OpenReadTest.cs program Listing 14.4: The ResponseHeadersTest.cs program Listing 14.5: The OpenWriteTest.cs program Listing 14.6: The UploadDataTest.cs program Listing 14.7: The UploadValuesTest.cs program Listing 14.8: The CredTest.cs program Listing 14.9: The CredCacheTest.cs program Listing 14.10: The WebGet.cs program Listing 14.11: The MathService.asmx program Listing 14.12: The ServiceTest.cs program Chapter 15: Active Directory Listing 15.1: The BindObject.cs program Listing 15.2: The GetProperties.cs program Listing 15.3: The ModifyProperty.cs program Listing 15.4: The AddProperty.cs program Listing 15.5: The ListObjects.cs program Listing 15.6: The AddObject.cs program Listing 15.7: The RemoveObject.cs program Listing 15.8: The DeleteObject.cs program Listing 15.9: The RenameObject.cs program Listing 15.10: The SimpleSearch.cs program Chapter 16: Remoting Listing 16.1: The SerialEmployee.cs program Listing 16.2: The SoapTest.cs program Listing 16.3: The soaptest.xml file Listing 16.4: The BinaryDataSender.cs program Listing 16.5: The BinaryDataRcvr.cs program Listing 16.6: The BetterDataSender.cs program Listing 16.7: The BetterDataRcvr.cs program Listing 16.8: The MathClass.cs program Listing 16.9: The server.xml configuration file] Listing 16.10: The MathServer.cs program Listing 16.11: The MathClient.cs program Listing 16.13: The soapsuds-generated MathClass.cs file Listing 16.14: The NewMathClient.cs program Chapter 17: Security Listing 17.1: The PickyTcpClient.cs program Listing 17.2: The PickyTcpListener.cs program Listing 17.3: The CryptoTest.cs program Listing 17.4: The CryptoDataSender.cs program Listing 17.5: The CryptoDataRcvr.cs program List of Sidebars Chapter 4: DNS and C# The History of Computer Names Control of Domain Names DNS Server Configurations and Windows Chapter 6: Connectionless Sockets Stopping the UDP Server Program Chapter 12: SNMP SNMP and MIB Versions Chapter 16: Remoting Performance Considerations ... NET uses the WinSock interface to access network resources Chapter 3, C# Network Programming Classes,” offers a quick introduction to the entire C# network libraries and shows the basic formats of the classes Chapter 4, “DNS and C# ,” rounds out the introductory section by showing... The next group of chapters presents the core of network programming topics in the book Each of these chapters discusses a major topic using in creating C# network programs Chapter 5, “Connection-Oriented Sockets,” starts the discussion of... using C# classes Combining the C# Forms library to write the graphical code with the C# Socket library to write the networking code makes creating professional network applications simple With C# network

Ngày đăng: 25/03/2019, 17:09

Từ khóa liên quan

Mục lục

  • Table of Contents

  • BackCover

  • C# Network Programming

  • Introduction

    • How This Book Is Organized

      • Part I: Network Programming Basics

      • Part II: Network Layer Programming

      • Part III: Application Layer Programming Examples

      • Keeping Up to Date

      • Part I: Network Programming Basics

        • Chapter 1: The C# Language

          • Basics of .NET

          • Installing a C# Development Environment

          • The C# Runtime Environment

          • C# Programming Basics

          • C# Features

          • Summary

          • Chapter 2: IP Programming Basics

            • Watching Network Traffic

            • Analyzing Network Packets

            • Programming with TCP and UDP

            • Finding IP Address Information

            • Summary

            • Chapter 3: C# Network Programming Classes

              • A Primer on Socket Programming

              • C# Socket Programming

Tài liệu cùng người dùng

Tài liệu liên quan