TCP/IP Sockets in C# : Practical Guide for Programmers
by David Makofske, Michael Donahoo, and Kenneth Calvert 
Publisher: Morgan Kaufmann; (March 30, 2004) 
ISBN: 0124660517 

CHAPTER 2 CODE README CONTENTS
------------------------------
I. Compiling and Running the Code Examples
II. Chapter 2 Code Description
III. Disclaimer
-----------------------------------------------------------------------------------

I. Compiling and Running the Code Examples

Most of the book's code was designed to be compiled and run from a command prompt. 
They may also be imported into Microsoft Visual Studio for compilation. Instructions
are given here for command line usage: 

1.) Go to the Microsoft Developer Network Site (http://msdn.microsoft.com/
netframework/technologyinfo/howtoget) and download and install the .NET Framework 
SDK (at the time of this writing version 1.1).

2.) Open a windows command prompt and run the sdkvars command to set your environment 
variables.

3.) To compile a single program, use the csc command with the source file name, for 
example: 

C:\>csc IPAddressExample.cs
Microsoft (R) Visual C# .NET Compiler version 7.10.3052.4
for Microsoft (R) .NET Framework version 1.1.4322
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.

This will create the .exe executable: 

C:\>dir

10/22/2003  03:40 PM             1,629 IPAddressExample.cs
03/12/2004  11:24 PM             4,096 IPAddressExample.exe

To run a program type the name of the program with a .exe extension or no extension 
along with any command-line arguments. 

C:\>IPAddressExample www.mkp.com

Local Host:
        tractor
        192.168.0.2
www.mkp.com:
        www.mkp.com
        129.35.78.178


To compile a single executable from several source code files, enter all the files 
on the same csc command: 

C:\>csc SendTcp.cs ItemQuote.cs ItemQuoteEncoder.cs ItemQuoteEncoderText.cs ItemQ
uoteTextConst.cs ItemQuoteDecoder.cs ItemQuoteDecoderBin.cs ItemQuoteBinConst.cs
Microsoft (R) Visual C# .NET Compiler version 7.10.3052.4
for Microsoft (R) .NET Framework version 1.1.4322
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.

4.) Batch files are supplied (ch2.bat, ch3.bat, ch4.bat and ch5.bat) to compile all 
the code for each chapter, typing the batch file name on the command prompt will 
compile all programs in the chapter's directory: 

C:\>ch2

Note: Some of the programs in Chapters 4 and 5 utilize source files from earlier 
chapters, as described in the download section. The batch files for Chapters 4 and 
5 will automatically look for these files in the appropriate chapter directory. You 
will need to download the entire archive or all required chapter zip files for these 
programs to compile correctly.  

-----------------------------------------------------------------------------------

II. Chapter 2 Code Description

Once you have installed the .NET SDK library and executed the sdkvars command, you 
can compile the entire Chapter 2 code contents by running ch2.bat. With the 
exception of the IPAddressExample program, all of the code in this chapter consists 
of various echo clients and servers. An echo server using the appropriate protocol 
(TCP or UDP) must be running for an echo client to talk to. Some of the client and 
server programs are deliberately coded to behave badly in order to test robustness 
of the program they are communicating with, and those programs are explicitly 
identified below.

The code for chapter 2 consists of the following executables:

1) IPAddressExample* - Illustrates DNS lookups. As arguments takes zero or more 
domain names or IP addresses to do a DNS lookup on.

2) TcpEchoClient* - client echo program using TCP with the TcpClient class. As 
arguments takes a server to send to, a text word to send (no spaces), and an 
optional port number to send to (default is 7).

3) TcpEchoServer* - server echo program using TCP with the TcpListener class. As 
an argument takes an optional port number to listen on (default is 7).

4) TcpEchoClientNoRead - client echo program using TCP that does not read server 
echo response. Can be used to test echo servers with misbehaving clients. As 
arguments takes a server to send to, a text word to send (no spaces), and an 
optional port number to send to (default is 7).

5) TcpEchoClientSocket* - client echo program using TCP with the Socket class. As 
arguments takes a server to send to, a text word to send (no spaces), and an 
optional port number to send to (default is 7).

6) TcpEchoServerSocket* - server echo program using TCP with the Socket class. As 
an argument takes an optional port number to listen on (default is 7).

7) TcpDeadEchoServer - server echo program using TCP that accepts connections but 
does not respond. Can be used to test echo clients with misbehaving servers. As an 
argument takes an optional port number to listen on (default is 7).

8) TcpSlowEchoServer - server echo program using TCP that emulates slow responses 
by sleeping before responding. Can be used to test echo clients with slow servers. 
As an argument takes an optional port number to listen on (default is 7).

9) UdpEchoClient* - client echo program using UDP with the UdpClient class. As 
arguments takes a server to send to, a text word to send (no spaces), and an 
optional port number to send to (default is 7).

10) UdpEchoServer* - server echo program using UDP with the UdpClient class. As an 
argument takes an optional port number to listen on (default is 7).

11) UdpEchoServerSocket* - server echo program using UDP with the Socket class. As 
an argument takes an optional port number to listen on (default is 7).

12) UdpEchoClientTimeoutSocket* - client echo program using UDP with the Socket 
class. Implements a wait timeout on the server response. As arguments takes a 
server to send to, a text word to send (no spaces), and an optional port number 
to send to (default is 7).

13) UdpDeadEchoServer - server echo program using UDP that reads datagrams but 
does not respond. Can be used to test UdpEchoClientTimeoutSocket.cs on localhost. 
As an argument takes an optional port number to listen on (default is 7).

14) TcpEchoPeekClient* - echo client using TCP with the Socket class. Illustrates 
using Peek to view contents of the receive buffer without removing them. As 
arguments takes a server to send to, a text word to send (no spaces), and an 
optional port number to send to (default is 7).

* See book for more detailed code explainations.

-----------------------------------------------------------------------------------

III. Disclaimer

The purpose of this book is to provide general information about network 
programming as of the book's publication date. The authors have included sample 
code that is intended for the sole purpose of illustrating the use of the sockets 
API. Neither the authors nor the publisher are aware of any third party patents or 
proprietary rights that may cover any sample of any kind. The authors and the 
Publisher DISCLAIM ALL EXPRESS AND IMPLIED WARRANTIES, including warranties of 
merchantability and fitness for any particular purpose. Your use or reliance upon 
any sample code or other information in this book will be at your own risk. No one 
should use any sample code (or illustrations) from this book in any software 
application without first obtaining competent legal advice. 
-----------------------------------------------------------------------------------