Home > Store

Linux Socket Programming

Register your product to gain access to bonus material or receive a coupon.

Linux Socket Programming

Book

  • This product currently is not for sale.
Not for Sale

Description

  • Copyright 2001
  • Edition: 1st
  • Book
  • ISBN-10: 0-672-31935-7
  • ISBN-13: 978-0-672-31935-8

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.

  • After reading this book, the reader will be able to:
  • Differentiate basic datagrams vs. streaming sockets.
  • Differentiate unicast, broadcast, and multicast sockets.
  • Write socket-based network programs.
  • Write portable code for various OS'.
  • Implement client-server and peer communications
  • Increase network throughput using "connectionless" communications
  • Manage asynchronous I/O, I/O and multiple sockets.
  • Use signals, threading and processes to manage socket connections.
  • Understand new socket technologies like Mbone and 6bone.
  • Understand Remote Procedure Calls and how to implement them.
  • Understand the different socket addressing types.

Downloads

Downloads


Appendix A in pdf format. - 131 KB -- appendix_a.pdf

Appendix B in pdf format. - 145 KB -- appendix_b.pdf

Appendix C in pdf format. - 146 KB -- appendix_c.pdf

Appendix D in pdf format. - 134 KB -- appendix_d.pdf

Appendix A in tar.gz and html format. - 2733 KB -- appendix_a.tar.gz

Appendix B in tar.gz and html format. - 16 KB -- appendix_b.tar.gz

Appendix C in tar.gz and html format. - 17 KB -- appendix_c.tar.gz

Appendix D in tar.gz and html format. - 11 KB -- appendix_d.tar.gz

Source code from the book. - 16 KB -- linuxsoc.tgz

Sample Content

Table of Contents



Introduction.

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.

Asynchronous I/O.

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.

Resource Management.

File Management. Memory Heap. Static Data Memory. CPU, Shared Memory, and Processes.

Critical Servers.

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.

Object Features.

The Class or Object. Attributes. Properties. Methods. Access Rights. Relationships.

Extending Objects.

Templates. Persistence. Streaming. Overloading. Interfaces. Events and Exceptions.

Special Forms.

Record/Structure. Function Bag.

Language Support.

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.

Implementation Limitations.

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.

C++ Exceptions.

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

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.

Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020