Welcome
Welcome to the website for Makofske, Donahoo, Calvert: TCP/IP Sockets in C#: Practical Guide for Programmers.
TCP/IP Sockets in C#
I. Code Downloads
II. Compiling and Running the Code
III. Errata
- complete zip archive - csharpsockets (66KB Zip File)
- chapter 2 - csharpsocketschap2 (22KB Zip File)
- chapter 3 - csharpsocketschap3 (9KB Zip File)
- chapter 4 - csharpsocketschap4 (30KB Zip File)
- chapter 5 - csharpsocketschap5 (3KB Zip File)
Contents of Zip Files
Zip Files by Chapter: Chapter 2: 02~chapter_2_-_csharpsocketschap2.zip
IPAddressExample.cs, IPAddressExample2.cs, TcpEchoClient.cs, TcpEchoServer.cs, TcpEchoClientSocket.cs, TcpEchoClientSocket2.cs, TcpEchoServerSocket.cs UdpEchoClient.cs, UdpEchoServer.cs, UdpEchoClientTimeoutSocket.cs, UdpEchoClientTimeoutSocket2.cs, UdpEchoServerSocket.cs, TcpEchoPeekClient.cs, TcpEchoPeekClient2.cs, TcpEchoClientGUI.cs, TcpDeadEchoServer.cs, TcpEchoClientNoRead.cs, TcpSlowEchoServer.cs, UdpDeadEchoServer.csChapter 3: 03~chapter_3_-_csharpsocketschap3.zip
Framer.cs, ItemQuote.cs, ItemQuoteBinConst.cs, ItemQuoteDecoder.cs, ItemQuoteDecoderBin.cs, ItemQuoteDecoderText.cs, ItemQuoteEncoder.cs, ItemQuoteEncoderBin.cs, ItemQuoteEncoderText.cs, ItemQuoteTextConst.cs, RecvTcp.cs, RecvUdp.cs, SendTcp.cs, SendUdp.csChapter 4: 04~chapter_4_-_csharpsocketschap4.zip
ConsoleLogger.cs, Dispatcher.cs, EchoProtocol.cs, EchoProtocolFactory.cs, FileLogger.cs, IDispatcher.cs, ILogger.cs, IProtocol.cs, IProtocolFactory.cs, MCIPAddress.cs, PoolDispatcher.cs, RecvUdpMulticast.cs1, SendUdpMulticast.cs2 TcpClientShutdown.cs, TcpEchoClientAsync.cs, TcpEchoClientAsyncSocket.cs, TcpEchoClientAsyncSocket2.cs, TcpEchoServerAsync.cs, TcpEchoServerPool.cs, TcpEchoServerSelectSocket.cs, TcpEchoServerThread.cs, TcpEchoServerTimeout.cs, TcpNBEchoClient.cs, TcpNBEchoClient2.cs, TcpPollEchoClient.cs, TcpPollEchoClient2.cs, ThreadExample.cs, ThreadMain.cs, ThreadPerDispatcher.cs, TimelimitEchoProtocolFactory.cs, TranscodeClient.cs, TranscodeServer.csChapter 5: 05~chapter_5_-_csharpsocketschap5.zip
TranscodeClientNoDeadlock.cs31 - Requires ItemQuote.cs, ItemQuoteTextConst.cs, Framer.cs, ItemQuoteDecoder.cs and ItemQuoteDecoderText.cs from Chapter 3.
2 - Requires ItemQuote.cs, ItemQuoteTextConst.cs, Framer.cs, ItemQuoteEncoder.cs and ItemQuoteEncoderText.cs from Chapter 3.
3 - Requires TcpClientShutdown.cs from Chapter 4.
II. Compiling and Running the Code
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) and download and install the .NET Framework SDK.
2. In .NET Framework versions 2.0 and higher, preconfigured command prompts are available from the Program Menu. Depending on your version you will go to:
Start -> All Programs -> Microsoft .NET Framework SDK v2.0 -> SDK Command Prompt
or:
Start -> All Programs -> Microsoft Windows SDK -> CMD ShellYou can also open a regular windows command prompt and run sdkvars.bat (v2.0 and lower) or SetEnv.Cmd (v3.0 and higher) to set your environment variables. If you are using SetEnv.Cmd you may need to use the /V:ON option when launching your command prompt.
Example of running sdkvars (Note: your sdkvars output may vary):C:\>sdkvars
C:\>Set Path=C:\Program Files\Microsoft.NET\SDK\v1.1\Bin\;C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\;C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\;C:\Program Files\MicrosoftVisual Studio .NET 2003\Common7\IDE\;C:\Program Files\Microsoft.NET\SDK\v1.1\Bin\;C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\;C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\;C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\bin;C:\Program Files\Microsoft.NET\SDK\v1.1\Bin
C:\>Set LIB=C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\lib\;"C:\Program Files\Microsoft.NET\SDK\v1.1\Lib\";C:\Program Files\Microsoft Visual Studio.NET 2003\Vc7\lib\;"C:\Program Files\Microsoft.NET\SDK\v1.1\Lib\";
C:\>Set INCLUDE=C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\;"C:\Program Files\Microsoft.NET\SDK\v1.1\include\";C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\;"C:\Program Files\Microsoft.NET\SDK\v1.1\include\";
C:\>Set NetSamplePath=C:\PROGRA~1\Microsoft.NET\SDK\v1.1\
C:\>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/200303:40 PM
1,629 IPAddressExample.cs
03/12/200411:24 PM
4,096 IPAddressExample.exeTo run a program type the name of the program with a .exe extension or no extension along with any command-line arguments.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.178To 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 ItemQuoteTextConst.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.
III. Errata
- In version 2.0 of the .NET Framework the System.Net.Dns.Resolve()and System.Net.Dns.GetHostByName() methods were deprecated and replaced bySystem.Net.Dns.GetHostEntry(). These methods were referenced in the followingfiles:
IPAddressExample.cs, TcpEchoClientSocket.cs, UdpEchoClientTimeoutSocket.cs,TcpEchoPeekClient.cs, TcpNBEchoClient.cs, TcpPollEchoClient.cs,and TcpEchoClientAsyncSocket.cs
The following v2.0 versions of these files were created using GetHostEntry():
IPAddressExample2.cs, TcpEchoClientSocket2.cs, UdpEchoClientTimeoutSocket2.cs,TcpEchoPeekClient2.cs, TcpNBEchoClient2.cs, TcpPollEchoClient2.cs,and TcpEchoClientAsyncSocket2.cs. - Page 51, line 13, this line of code:
Console.WriteLine("echoed {0} bytes.", totalBytesRcvd);
Should read:
Console.WriteLine("echoed {0} bytes.", totalBytesEchoed);
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.
Disclaimer
Information provided in this document is provided "as is" without warranty of any kind, either express or implied. Every effort has been made to ensure accuracy and conformance to standards accepted at the time of publication. The reader is advised to research other sources of information on these topics.
The user assumes the entire risk as to the accuracy and the use of this document. This document may be copied and distributed subject to the following conditions:
All text must be copied without modification and all pages must be included;
All copies must contain the appropriate copyright notice and any other notices provided therein; and
This document may not be distributed for profit.