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 4 CODE README CONTENTS
------------------------------
I. Compiling and Running the Code Examples
II. Chapter 4 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 4 Code Description

Once you have installed the .NET SDK library and executed the sdkvars command, 
you can compile the entire Chapter 4 code contents by running ch4.bat. An echo 
server using the appropriate protocol (TCP or UDP) must be running for an echo 
client to talk to. The standard echo servers and clients from Chapter 2 can be
used for this purpose. Note that some executables below require source code 
from Chapter 3 to compile, and the ch4.bat file expects to find these files 
in the ..\ch3 directory.

The code for Chapter 4 consists of the following executables:

1.) TcpNBEchoClient* - client echo program using TCP that illustrates non-
blocking sockets. 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).

2.) TcpPollEchoClient* - client echo program using TCP that illustrates polling
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.) TcpEchoServerSelectSocket* - server echo program using TCP that illustrates 
the select statement. As an argument takes an optional port number to listen on 
(default is 7).

4.) TcpEchoServerTimeout* - server echo program using TCP that illustrates 
socket timeouts. As an argument takes an optional port number to listen on 
(default is 7).

5.) ThreadExample* - multithreaded program example. Takes no arguments.

6.) TcpEchoServerThread* - server echo program using TCP that is multi-threaded.
As an argument takes a port number to listen on. 

7.) ThreadMain* - server echo program using TCP that allows you to specify an 
echo protocol and dispatcher on the command line. As arguments takes a port to 
listen on, a protocol (Echo or TimelimitEcho) and a dispatcher (ThreadPer or Pool).

8.) TcpEchoServerPool* - server echo program using TCP that uses a pool of 
threads to handle requests. Takes as arguments a port number to listen on and
the number of threads in the pool.

9.) RecvUdpMulticast* - a multicast receiver program that receives an ItemQuote
from the SendUdpMulticast program. As arguments takes a multicast address (in
the range 224.0.0.0 - 239.255.255.255) and port number to listen on. This 
executable requires some source files from Chapter 3, and the ch4.bat file expects
to find these files in the ../ch3 directory.

10.) SendUdpMulticast* - a multicast send program that sends an ItemQuote to 
the RecvUdpMulticast program. As arguments takes a multicast address (in the
range 224.0.0.0 - 239.255.255.255) and port number to send on, and an optional
time-to-live (TTL).  This executable requires some source files from Chapter 3, 
and the ch4.bat file expects to find these files in the ../ch3 directory.

11.) TcpEchoClientAsync* - client echo program using TCP with the TcpClient
class that illustrates asynchronous sockets. 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).

12.) TcpEchoClientAsyncSocket* - client echo program using TCP with the Socket
class that illustrates asynchronous sockets. 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.) TcpEchoServerAsync* - server echo program using TCP that illustrates 
asynchronous sockets. As an argument takes an optional port number to listen on 
(default is 7).

14.) TranscodeClient* - client that sends a Unicode encoded file to the Transcode-
Server and receives back a UTF-8 encoded version of the file. As arguments takes
the server and port to send to, and the filename of the Unicode file to send.
SampleUnicode.txt is included in this zip file. Note this program has a flaw
that causes it to deadlock when sending large files, as described in the book.
The Chapter 5 program TranscodeClientNoDeadlock corrects this problem.

15.) TranscodeServer* - server that receives a Unicode encoded file from the 
TranscodeClient and sends back a UTF-8 encoded version of the file. As arguments
takes a port to listen on.

* 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. 
-----------------------------------------------------------------------------------