Register your product to gain access to bonus material or receive a coupon.
This book teaches readers how to program Linux sockets, and gives them everything they need to know to make programs communicate effetively over networks.
It presents a comprehensive discussion of all relevant topics including: writing programs compatible with both Internet Protocol version 4 (IPv4) and IPv6, raw sockets, User Datagram Protocol (UDP), broadcasting /multicasting, server internals, and more, plus a section covering Posix threads.
It provides thorough coverage of programming with the TCP, UDP, and IP protocols, as well as lower-level raw sockets. The myriad of function calls, data structures, and options associated with the APIs are explained with well-chosen diagrams and tables.
Datagrams and Multicasting (Part 1)
Datagrams and Multicasting (Part 2)
Securing Sockets with OpenSSL (Part 1)
Securing Sockets with OpenSSL (Part 2)
Writing a C-based Client/Server
I. NETWORK PROGRAMMING FROM THE CLIENT PERSPECTIVE.1. Introducing the Cookbook Network Client.
Connecting the World with Sockets. Talking the Talk: TCP/IP Addressing Overview. Hearing the Server: The Client's Basic Algorithm.
The Socket System Call: Procedures and Caveats. Making the Call: Connecting to the Server. Getting the Server's Reply. Closing the Connection.
Summary: What's Going On Behind the Scenes?2. TCP/IP Network Language Fluency.
An IP Numbering Overview.
Computer Identification. Internet ID Organization. Subnetwork Masks. Routers and Address Resolution. Special and Dwindling Addresses.
IP Host Port Numbers. Network Byte Ordering.
Using Internet Conversion Tools. Applying the Tools and Extending the Client.
Different Kinds of sockaddr. UNIX Named Pipes. Summary: Applying IP Numbering and Tools.3. Different Types of Internet Packets.
The Fundamental Network Packet.
version Field. header_len Field. serve_type Field. ID Field. dont_frag, more_frags, frag_offset Flags and Field. time_to_live (TTL) Field. protocol Field. options Field. data Field.
Dissecting the Various Packets.
Considering the Packet's Issues. Packet Types.
How the IP Protocols Fit Together. Snooping the Network with Tcpdump. Writing a Custom Network Snooper. Summary: Choosing the Best Packets for Sending Messages.4. Sending Messages Between Peers.
What Are Connection-Based Sockets?
Open Channels Between Programs. Reliable Communications. Lower Protocol Connections.
Example: Connecting to the HTTP Daemon.
Simplified HTTP Protocol. Getting an HTTP Page.
What Are Connectionless Sockets?
Setting the Socket's Address. Some Programs Just Need the Message. Transaction TCP (T/TCP): A Connectionless TCP.
Sending a Direct Message.
Binding the Port to Your Socket. Tossing the Message Around. Catching the Message.
Ensuring UDP Message Arrival.
Strengthening UDP's Reliability. Sequencing Packets. Packet Redundancy. Verifying Data Integrity. Data Flow Glitches.
Juggling Tasks: A Multitasking Introduction. Summary: Connected Versus Connectionless Models.5. Understanding the Network Layering Model.
Solving the Network Challenge.
Networking Hardware Issues. Networking Transmission Issues. Network to Operating System Interfacing. Network to Program Interfacing.
Open Systems Interconnection (OSI) Network Model.
Layer 1: Physical. Layer 2: Datalink. Layer 3: Network. Layer 4: Transport. Layer 5: Session. Layer 6: Presentation. Layer 7: Application.
Internet Protocol Suite.
Layer 1: Network Access Layer. Layer 2: Internetwork Layer (IP). Layer 2: Control/Error Messaging Extensions (ICMP). Layer 3: Host to Host (UDP). Layer 3: Host Streams (TCP). Layer 4: Application Layer.
Fundamental Differences Between OSI and IP. What Services What? Summary: From Theory to Application.
II. THE SERVER PERSPECTIVE AND LOAD CONTROL.6. A Server Primer.
Mapping the Socket: The Server's General Program Flow. A Simple Echo Server.
Binding Ports to the Socket. Creating a Socket Listening Queue. Accepting Client Connections. Communicating with the Client.
General Rules About Defining Protocols.
Which Program Talks First? Which Program Drives the Conversation? What Level of Certification Do You Need? What Type of Data Do You Use? How Do You Handle Binary Data? How Do You Know when There Is a Deadlock? Do You Need Clock Synchronization? How and When Do You Restart the Connection? When Are You Finished?
An Extended Example: An HTTP Directory Server. Summary: The Server's Basic Elements.7. Dividing the Load: Multitasking.
Defining Multitasking: Processes Versus Threads.
When to Use Multitasking. Multitasking Characteristics. Task Differences. How Do I Create a Process? How Do I Create a Thread? The __clone() System Call: The Call for the Brave. Task Communication.
Beating the Clock: Race Conditions and Mutexs.
Race Conditions. Mutual Exclusion (Mutex). Pthread Mutex Problems. Deadlock Prevention.
Controlling Children and Killing Zombies.
Give the Child More Attention: Priority and Scheduling. Burying the Zombies: Cleaning Up after Termination.
Extending Current Clients and Servers. Calling External Programs with the exec Server. Summary: Distributing the Process Load.8. Choosing when to Wait for I/O.
I/O Blocking: Why? When Do I Block? Alternatives to I/O Blocking. Comparing the Different I/O Programming Interactions. Polling I/O.
A Polling Reader. Polling Writer. Polling Connections.
On-Demand Reading. Asynchronous Writes. On-Demand Connections.
Solving Unwanted I/O Blocking with poll() and select().Implementing Timeouts. Summary: Choosing the I/O Techniques.9. Breaking Performance Barriers.
Creating the Servlets Before the Client Arrives.
Placing a Cap on the Number of Client Connections. Preforking Your Servers. Adapting to Different Load Levels.
Extending Control with a Smart Select.
The Scheduler Storm. Overburdened select().Compromising with a Smart Select. Implementation Problems. Redistributing the Load.
Delving Deeper into Socket Control.
General Options. IP-Specific Socket Options. IPv6-Specific Socket Options. TCP-Specific Socket Options.
Recovering the Socket Descriptor. Sending Before Received: Message Interleave. Noting File I/O Problems. Using Demand-Based I/O to Recover CPU Time.
Speeding Up a send().Offloading the recv().
Sending High-Priority Messages. Summary: Pulling Together Performance Features.10. Designing Robust Linux Sockets.
Using Conversion Tools. Eyeing Return Values. Capturing Signals.
SIGPIPE. SIGURG. SIGCHLD. SIGHUP. SIGIO. SIGALRM.
File Management. Memory Heap. Static Data Memory. CPU, Shared Memory, and Processes.
What Qualifies as a Critical Server? Communication Events and Interruptions. Session Recovery Issues. Session Recovery Techniques.
Client/Server Concurrency Issues.
Network Deadlock. Network Starvation.
Denial of Service Attacks. Summary: Solid-as-a-Rock Servers.
III. LOOKING AT SOCKETS OBJECTIVELY.11. Saving Time with Objects.
The Software Engineering Evolution.
Step-by-Step Functional Programming. Hiding Implementation with Modular Programming. Not Needing the Details: Abstract Programming. Getting Close to Nature Through Object Programming.
Reaching Programming Nirvana.
Reusing Your Work. Strengthening Reuse with Pluggability.
Laying the Object Foundation.
Implementation Encapsulation. Behavior Inheritance. Data Abstraction. Method Polymorphism.
The Class or Object. Attributes. Properties. Methods. Access Rights. Relationships.
Templates. Persistence. Streaming. Overloading. Interfaces. Events and Exceptions.
Record/Structure. Function Bag.
Supporting Versus Enabled Versus Oriented. How to Map Objects to Non-Object Languages.
Summary: Object-Oriented Thinking.12. Using Java's Networking API.
Exploring Different Java Sockets.
Programming Clients and Servers. Implementing Messengers. Sending to Multiple Destinations.
Connecting Through I/O.
Classifying the I/O Classes. Converting Between I/O Classes.
Configuring the Java Socket.
Shared Java-Socket Configurations. Java Multicast-Specific Configurations.
Multitasking the Programs.
Threading a Class. Adding Threads to a Class. Synchronizing Methods.
Implementation Limitations. Summary: Java-Style Network Programming.13. Designing and Using a C++ Socket Framework.
Why Use C++ for Sockets Programming?
Simplifying Sockets Interfacing. Hiding Implementation Details. Deploying Reusable Components with Easy to Use Interfaces. Demonstrating the Framework Design Processes.
Laying Out the Framework.
Defining the General Features. Grouping into Major Components. Creating the Framework Hierarchy. Defining Each Class's Capabilities.
Testing the Socket Framework.
The Echo Client/Server. Multitasking Peer-to-Peer.
Sending Unknown/Undefined Messages. Adding Multitasking.
Summary: A C++ Socket Framework Simplifies Programming.14. Limits to Objects.
Mind Over Objects.
Beginning on the Right Foot. A Blender Is Not an Object. Separating Analysis from Design. The Right Level of Detail. The Inheritance Explosion. Reuse-Misuse. Using C++'s friend Correctly. The Overloaded Operator.
Objects Don't Solve Everything.
Fads Come and Evolve. Inheritance Infection. Unreachable Code.
Complexity Give and Take.
Simplifying Programs with Established Interfaces. Multiple Inheritance Conundrum. Code Bloat.
Project Management Dilemma.
Getting the Right People at the Right Time. WISCY (“Whiskey”) Phenomenon. Testing (Dis-)Integration.
Summary: Walk Carefully on Shale.
IV. ADVANCED SOCKETS-ADDING VALUE.15. Network Encapsulation with Remote Procedure Calls (RPCs).
Revisiting the OSI Model. Comparing Network and Procedural Programming.
Language Limits. Holding Connected Sessions.
Supplying Middleware Methods.
Stubbing Network Calls. Adding the Service Call Implementation. Implementing the Presentation Layer.
Creating RPCs with rpcgen.
rpcgen's Interface Language.
Creating Non-Stateless Calls with Open Connections.
Diagnosing the State Problem. Remembering Where You Are. Following a Specific Route. Recovering from a State Failure.
Summary: Creating an RPC Toolset.16. Adding Security to Network Programs and SSL.
Giving Permission to Work.
Levels of Identification. Forms of Interchange.
The Problem with the Internet.
Everything Is Visible. Forms of Intrusion/Attack. TCP/IP Crackability.
Securing a Network Node.
Restricting Access. Firewalls. Demilitarized Zones (DMZs). Securing the Channel.
Encrypting the Messages.
What Are the Available Encryption Types?. Published Encryption Algorithms. Problems with Encryption.
Secure Sockets Layer (SSL).
Using OpenSSL. Creating an SSL Client. Creating an SSL Server.
Summary: The Secure Server.17. Sharing Messages with Multicast, Broadcast, and Mbone.
Broadcasting Messages to a Domain.
Revisiting IP Structure. Programming to Enable Broadcasting. Broadcasting Limitations.
Multicasting Messages to a Group.
Joining Multicast Groups. Sending a Multicast Message. How the Network Provides Multicasting. Getting Out the Multicast Message. Multicasting Limitations.
Summary: Efficient Message Sharing.18. The Power of Raw Sockets.
When Would You Use Raw Sockets?
Exposing the ICMP. Controlling the IP Header. Speeding Through the Physical Network.
What Are the Limitations? Putting Raw Sockets to Work.
Selecting the Right Protocol. Creating an ICMP Packet. Calculating a Checksum. Controlling the IP Header. Third-Party Traffic.
How Does Ping Work?
The MyPing Receiver. The MyPing Sender.
How Does Traceroute Work? Summary: Making the Raw Decisions.19. IPv6: The Next Generation to IP.
Current Addressing Problems.
Solving the Dwindling IPv4 Address Space. What Does IPv6 Look Like? How Do IPv4 and IPv6 Work Together?
Trying Out IPv6.
Configuring the Kernel. Configuring the Tools. Converting IPv4 Calls to IPv6. Converting Raw Sockets to IPv6. Converting ICMPv6 Sockets to IPv6. The New Multicast Protocol.
IPv6 Pros and Cons.
Expected Linux Incorporation.
Summary: Moving Your Code into the Future.
V. APPENDIXES.Appendix A: Data Tables.
Domains: First Parameter to socket(). Types: Second Parameter to socket(). Protocol Definitions. Standard Internet Port Assignments (First 100 Ports). HTTP 1.1 Status Codes. Socket Options (get/setsockopt()). Signal Definitions. ICMP Codes. IPv4 Multicast Allocation. Proposed IPv6 Address Allocation. ICMPv6 Codes. IPv6 Multicast Scope Field. IPv6 Multicast Flags Field.Appendix B: Networking API.
Connecting to the Network. Communicating on a Channel. Terminating Connections. Network Data Conversions. Network Addressing Tools. Socket Controls.Appendix C: Kernel API Subset.
Tasks. Threads. Locking. Signals. Files and So On.Appendix D: Object Classes.
Exception (Superclass). NetException (Class).
C++ Support Classes.
SimpleString (Class). HostAddress (Class).
C++ Messaging Classes.
Message (Abstract Class). TextMessage (Class).
C++ Socket Classes.
Socket (Superclass). SocketStream (Class). SocketServer (Class). SocketClient (Class). Datagram (Class). Broadcast (Class). MessageGroup (Class).
java.io.IOException (Class). java.net.SocketException (Class).
Java Support Classes.
java.net.DatagramPacket (Class). java.net.InetAddress (Class).
Java I/O Classes.
java.io.InputStream (Abstract Class). java.io.ByteArrayInputStream (Class). java.io.ObjectInputStream (Class). java.io.OutputStream (Abstract Class). java.io.ByteArrayOutputStream (Class). java.io.ObjectOutputStream (Class). java.io.BufferedReader (Class). java.io.PrintWriter (Class).
Java Socket Classes.
java.net.Socket (Class). java.net.ServerSocket (Class). java.net.DatagramSocket (Class). java.net.MulticastSocket (Class).Index.