TCP/IP Sockets in C: Practical Guide for Programmers, Second Edition is a quick and affordable way to gain the knowledge and skills needed to develop sophisticated and powerful web-based applications. The book's focused, tutorial-based approach enables the reader to master the tasks and techniques essential to virtually all client-server projects using sockets in C. This edition has been expanded to include new advancements such as support for IPv6 as well as detailed defensive programming strategies.
If you program using Java, be sure to check out this book's companion, TCP/IP Sockets in Java: Practical Guide for Programmers, 2nd Edition.
- Includes completely new and expanded sections that address the IPv6 network environment, defensive programming, and the select() system call, thereby allowing the reader to program in accordance with the most current standards for internetworking.
- Streamlined and concise tutelage in conjunction with line-by-line code commentary allows readers to quickly program web-based applications without having to wade through unrelated and discursive networking tenets.
Inhaltsverzeichnis
1;Front Cover;1 2;TCP/IP Sockets in C;4 3;Copyright Page;5 4;Table of Contents;6 5;Preface to the Second Edition;10 6;Chapter 1. Introduction;16 6.1;1.1 Networks, Packets, and Protocols;16 6.2;1.2 About Addresses;19 6.2.1;1.2.1 Writing Down IP Addresses;19 6.2.2;1.2.2 Dealing with Two Versions;20 6.2.3;1.2.3 Port Numbers;20 6.2.4;1.2.4 Special Addresses;21 6.3;1.3 About Names;22 6.4;1.4 Clients and Servers;22 6.5;1.5 What Is a Socket?;23 6.6;Exercises;24 7;Chapter 2. Basic TCP Sockets;26 7.1;2.1 IPv4 TCP Client;26 7.2;2.2 IPv4 TCP Server;32 7.3;2.3 Creating and Destroying Sockets;37 7.4;2.4 Specifying Addresses;38 7.4.1;2.4.1 Generic Addresses;38 7.4.2;2.4.2 IPv4 Addresses;39 7.4.3;2.4.3 IPv6 Addresses;39 7.4.4;2.4.4 Generic Address Storage;40 7.4.5;2.4.5 Binary/String Address Conversion;41 7.4.6;2.4.6 Getting a Sockets Associated Addresses;41 7.5;2.5 Connecting a Socket;42 7.6;2.6 Binding to an Address;42 7.7;2.7 Handling Incoming Connections;43 7.8;2.8 Communication;45 7.9;2.9 Using IPv6;45 7.10;Exercises;47 8;Chapter 3. Of Names and Address Families;50 8.1;3.1 Mapping Names to Numbers;50 8.1.1;3.1.1 Accessing the Name Service;51 8.1.2;3.1.2 Details, Details;55 8.2;3.2 Writing Address-Generic Code;56 8.2.1;3.2.1 Generic TCP Client;58 8.2.2;3.2.2 Generic TCP Server;61 8.2.3;3.2.3 IPv4IPv6 Interoperation;64 8.3;3.3 Getting Names from Numbers;65 8.4;Exercises;66 9;Chapter 4. Using UDP Sockets;68 9.1;4.1 UDP Client;69 9.2;4.2 UDP Server;72 9.3;4.3 Sending and Receiving with UDP Sockets;75 9.4;4.4 Connecting a UDP Socket;76 9.5;Exercises;77 10;Chapter 5. Sending and Receiving Data;78 10.1;5.1 Encoding Integers;79 10.1.1;5.1.1 Sizes of Integers;79 10.1.2;5.1.2 Byte Ordering;81 10.1.3;5.1.3 Signedness and Sign Extension;82 10.1.4;5.1.4 Encoding Integers by Hand;83 10.1.5;5.1.5 Wrapping TCP Sockets in Streams;86 10.1.6;5.1.6 Structure Overlays: Alignment and Padding;88 10.1.7;5.1.7 Strings and Text;91 10.1.8;5.1.8 Bit-Diddling: Encoding Booleans;93 10.2;5.2 Constructing,
Framing, and Parsing Messages;94 10.2.1;5.2.1 Framing;101 10.2.2;5.2.2 Text-Based Message Encoding;106 10.2.3;5.2.3 Binary Message Encoding;109 10.2.4;5.2.4 Putting It All Together;111 10.3;5.3 Wrapping Up;112 10.4;Exercises;112 11;Chapter 6. Beyond Basic Socket Programming;114 11.1;6.1 Socket Options;114 11.2;6.2 Signals;115 11.3;6.3 Nonblocking I/O;121 11.3.1;6.3.1 Nonblocking Sockets;122 11.3.2;6.3.2 Asynchronous I/O;123 11.3.3;6.3.3 Timeouts;127 11.4;6.4 Multitasking;131 11.4.1;6.4.1 Per-Client Processes;132 11.4.2;6.4.2 Per-Client Thread;138 11.4.3;6.4.3 Constrained Multitasking;141 11.5;6.5 Multiplexing;143 11.6;6.6 Multiple Recipients;148 11.6.1;6.6.1 Broadcast;149 11.6.2;6.6.2 Multicast;152 11.6.3;6.6.3 Broadcast vs. Multicast;157 11.7;Exercises;157 12;Chapter 7. Under the Hood;158 12.1;7.1 Buffering and TCP;160 12.2;7.2 Deadlock Danger;163 12.3;7.3 Performance Implications;164 12.4;7.4 TCP Socket Life Cycle;165 12.4.1;7.4.1 Connecting;165 12.4.2;7.4.2 Closing a TCP Connection;169 12.5;7.5 Demultiplexing Demystified;173 12.6;Exercises;175 13;Chapter 8. Socket Programming in C++*;176 13.1;8.1 PracticalSocket Library Overview;177 13.2;8.2 Plus One Service;179 13.2.1;8.2.1 Plus One Server;179 13.2.2;8.2.2 Plus One Client;181 13.2.3;8.2.3 Running Server and Client;183 13.3;Exercises;183 13.4;8.3 Survey Service;183 13.4.1;8.3.1 Survey Support Functions;184 13.4.2;8.3.2 Survey Server;187 13.4.3;8.3.3 Survey Client;191 13.4.4;8.3.4 Running Server and Client;193 13.5;8.4 Survey Service, Mark 2;193 13.5.1;8.4.1 Socket Address Support;194 13.5.2;8.4.2 Socket iostream Interface;195 13.5.3;8.4.3 Enhanced Survey Server;196 13.5.4;8.4.4 Enhanced Survey Client;201 13.5.5;8.4.5 Administrative Client;202 13.5.6;8.4.6 Running Server and Clients;203 13.6;Exercises;204 14;References;206 15;Index;208