ebook img

Sockets in C Sharp. Practical Guide for Programmers PDF

188 Pages·2004·1.66 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Sockets in C Sharp. Practical Guide for Programmers

TCP/IP Sockets in C# Practical Guide for Programmers The Morgan Kaufmann Practical Guides Series Series Editor: Michael J. Donahoo TCP/IPSocketsinC#:PracticalGuideforProgrammers DavidMakofske,MichaelJ.Donahoo,andKennethL.Calvert JavaCryptographyExtensions:PracticalGuideforProgrammers JasonWeiss JSP:PracticalGuideforJavaProgrammers RobertJ.Brunner JSTL:PracticalGuideforJSPProgrammers SueSpielman Java:PracticalGuideforProgrammers ZbigniewM.Sikora TheStrutsFramework:PracticalGuideforJavaProgrammers SueSpielman MulticastSockets:PracticalGuideforProgrammers DavidMakofskeandKevinAlmeroth TCP/IPSocketsinJava:PracticalGuideforProgrammers KennethL.CalvertandMichaelJ.Donahoo TCP/IPSocketsinC:PracticalGuideforProgrammers MichaelJ.DonahooandKennethL.Calvert JDBC:PracticalGuideforJavaProgrammers GregoryD.Speegle Forfurtherinformationonthesebooksandforalistofforthcomingtitles, pleasevisitourwebsiteathttp://www.mkp.com/practical TCP/IP Sockets in C# Practical Guide for Programmers David B. Makofske Akamai Technologies Michael J. Donahoo Baylor University Kenneth L. Calvert University of Kentucky AMSTERDAM•BOSTON•HEIDELBERG•LONDON NEWYORK•OXFORD•PARIS•SANDIEGO SANFRANCISCO•SINGAPORE•SYDNEY•TOKYO MorganKaufmannisanimprintofElsevier SeniorEditor RickAdams AssociateEditor KarynJohnson PublishingServicesManager SimonCrump ProjectManager KyleSarofeen CoverDesign YvoNiezebosDesign CoverImage GettyImages Composition CephaImagingPvt.Ltd. Copyeditor HarbourFraserHodder Proofreader JacquiBrownstein Indexer MichaelFerreira Interiorprinter MaplePress Coverprinter PhoenixColor MorganKaufmannPublishersisanimprintofElsevier. 500SansomeStreet,Suite400,SanFrancisco,CA94111 Thisbookisprintedonacid-freepaper. ©2004byElsevierInc.Allrightsreserved. Designationsusedbycompaniestodistinguishtheirproductsareoftenclaimedastrademarksor registeredtrademarks.InallinstancesinwhichMorganKaufmannPublishersisawareofaclaim, theproductnamesappearininitialcapitalorallcapitalletters.Readers,however,shouldcontact theappropriatecompaniesformorecompleteinformationregardingtrademarksandregistration. Nopartofthispublicationmaybereproduced,storedinaretrievalsystem,ortransmittedinany formorbyanymeans—electronic,mechanical,photocopying,scanning,orotherwise—withoutprior writtenpermissionofthepublisher. PermissionsmaybesoughtdirectlyfromElsevier’sScience&TechnologyRightsDepartmentin Oxford,UK:phone:(+44)1865843830,fax:(+44)1865853333,e-mail:[email protected]. Youmayalsocompleteyourrequeston-lineviatheElsevierhomepage(http://elsevier.com)by selecting“CustomerSupport”andthen“ObtainingPermissions.” LibraryofCongressCataloging-in-PublicationData Applicationsubmitted. ISBN:0-12-466051-7 ForinformationonallMorganKaufmannpublications, visitourWebsiteatwww.mkp.com PrintedintheUnitedStatesofAmerica 08 07 06 05 04 5 4 3 2 1 ForMargieandJacob,fortheirloveandinspiration –David Formythreegirls:Lisa,Michaela,andMackenzie –Jeff Formyparents,PaulandEleanorCalvert –Ken This Page Intentionally Left Blank Contents Preface ix 1 Introduction 1 1.1 Networks,Packets,andProtocols 1 1.2 AboutAddresses 4 1.3 AboutNames 5 1.4 ClientsandServers 5 1.5 WhatIsaSocket? 6 1.6 Exercises 7 2 Basic Sockets 9 2.1 SocketAddresses 9 2.2 SocketImplementationin.NET 15 2.3 TCPSockets 16 2.4 UDPSockets 29 2.5 The.NETSocketClass 37 2.6 Exercises 57 3 Sending and Receiving Messages 59 3.1 EncodingInformation 61 3.2 ComposingI/OStreams 65 3.3 FramingandParsing 66 3.4 ImplementingWireFormatsinC# 70 3.5 WrappingUp 83 3.6 Exercises 84 vii viii Contents ■ 4 Beyond the Basics 85 4.1 NonblockingI/O 85 4.2 Multiplexing 95 4.3 Threads 99 4.4 AsynchronousI/O 117 4.5 MultipleRecipients 131 4.6 ClosingConnections 138 4.7 WrappingUp 145 4.8 Exercises 146 5 Under the Hood 147 5.1 BufferingandTCP 149 5.2 BufferDeadlock 152 5.3 PerformanceImplications 154 5.4 TCPSocketLifeCycle 155 5.5 DemultiplexingDemystified 165 5.6 Exercises 167 Appendix:HandlingSocketErrors 169 Bibliography 171 Index 173 Preface Foryears,collegecoursesincomputernetworkingweretaughtwithlittleorno“handson” experience. For various reasons, including some good ones, instructors approached the principles of computer networking primarily through equations, analyses, and abstract descriptionsofprotocolstacks.Textbooksmightincludecode,butitwasunconnectedto anythingstudentscouldgettheirhandson. Perhapsinanidealworldthiswouldsuffice, but we believe that students learn better when they can see (and then build) concrete examplesoftheprinciplesatwork.Fortunately,suchexamplesaboundtoday.TheInternet has become a part of everyday life, and access to its services is readily available to most students(andtheirprograms). The Berkeley Sockets interface, known universally as “sockets” for short, is the de facto standard application programming interface (API) for networking, spanning a wide range of operating systems. The sockets API was designed to provide generic access to interprocess communication services that might be implemented by whatever protocols were supported on a particular platform—IPX, Appletalk, TCP/IP, and so on. As a conse- quence of this generic approach the sockets API may appear dauntingly complicated at first. But, in fact, the basics of network programming using the Internet (TCP/IP) proto- cols are not difficult. The sockets interface has been around for a long time—at least in “Internettime”—butitislikelytoremainimportantfortheforeseeablefuture. We have written this book to improve the support for socket-based programming exercises in our own networking courses. Although some networking texts deal with net- workprogramming,weknowofnonethatcoverTCP/IPsockets.Excellentreferencebooks onTCP/IPsocketprogrammingexist,buttheyaretoolargeandcomprehensivetobecon- sidered as a supplement to a networking text. Our goal, therefore, is to provide a gentle ix

Description:
"TCP/IP sockets in C# is an excellent book for anyone interested in writing network applications using Microsoft .Net frameworks. It is a unique combination of well written concise text and rich carefully selected set of working examples. For the beginner of network programming, it's a good starting
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.