
Master POSIX socket programming by building a multithreaded TCP/IP server library. Multiplex clients, implement graceful shutdown, keep-alive, message demarcation, client migration, and per-client statistics.
End product: a c++ dcp server library enabling multiple dcp servers, notifying apps of client activity via rtc ps server library, and supporting protocols like ftp on the dcp infrastructure.
Create and manage a GitHub repository for this course and set up a GitHub account to develop the DCB server library, while exploring GCP internals and TCP/IP theory for knowledge.
Configure a DCP server to listen on a user-specified IP address and port, handle multiple client connections via multithreading, multiprocessing, or multiplexing, and support graceful shutdown.
Outline the DCP server architecture with four components—the ECP central controller, connection acceptor service, client database management service, and data request service—and show their interactions with the user application.
Explore the DCP server architecture with three components—the connection acceptor service, the data request service, and the client manager—each running in its own thread, coordinated by the DCP server controller.
Explore how a new client connection initiation (SYN) is handled: accept, create a DCP client object, update the client database, and start the DRC service to listen for data.
Create a new project from scratch and add files for the DCP server components, including the DCP server controller, connection acceptor, database manager, and service manager, with start and stop.
Set up a build by compiling the project with the Makefile, add a mean function to the test file, and update the Makefile to include new source files.
Define constructors for the DCP server controller and its services to initialize CAC, DBM, Asante, and RS, then initialize and start the server using the test harness.
Implement the start method of the dhcp server controller to launch the series thread, initialize dbms, and start the connection acceptor, client service manager, and client database manager.
Implement a DCP New Connection Acceptor to initialize a socket, create an accept file descriptor, and spawn a pthread-based thread that listens for new client connections on the TCP server.
Implement the start_connection function to launch a service thread that accepts new client connections for the DCB server, running in an infinite loop, using essential multithreading concepts.
Start a dedicated thread for the DCP new connection acceptor, loop indefinitely to accept new connections, and expose an internal function to access private members for managing the communication socket.
The TCP server creates a DCP client object on new connections, stores it in the client database, and starts listening for data on the client's socket.
Design a callback-based notification where TCP server informs the user application of new client connections by registering callbacks with the DCP controller, with future support for disconnects and messages.
Define function pointers in the tcp server controller, have the application call set server notification callbacks to register, and enable the library to notify connect, disconnect, and message events.
Implement the display APIs for the DCP server controller to print the server's IP and port and each connected client's IP address and port by iterating the client database.
Begin implementing the discipline service manager, the client data request service of the DCP server, and explore its role alongside the CSC service and the client database manager.
The drc service on the ecp server relays messages from clients to the user application for processing. It runs as a thread that uses select and maintains a client database.
Explains how the DCP server listens on a newly connected client file descriptor, updates the client database, and starts listening via the process new client API using multiplexed select.
Start the DCP client service manager thread to implement the data request service, initialize max file descriptor, and maintain active and backup file descriptor sets for select.
Learn to multiplex multiple clients with the select system call in a POSIX TCP server, by managing active and backup file descriptor sets and reading data into a shared buffer.
Include all connected client file descriptors from the DRC client database in the multiplexing loop by fixing the max fd and copying descriptors into the backup file descriptor set.
Learn to cancel the DRC thread by leveraging cancellation points and theory from appendices E, B1, and B2, and implement the stop CCP Client Service Manager API.
Implement a public API to stop the DCP client service manager thread by signaling cancellation with pthread_cancel, joining with pthread_join, and relying on default cancellation.
Learn to safely add a new client fd to the select loop by canceling the virus thread and updating the DRC client database before restarting the listener.
Explore the tcp message boundary problem, showing how tcp treats data as a byte stream with circular buffers, possibly splitting or coalescing messages, so applications must define boundaries.
The demo shows the TCP byte oriented nature, as a receiver gets data in variable sizes while a sender streams messages, with TCP assembling or splitting segments.
Understand how tcp's byte oriented design requires application level boundary recognition to frame messages. Explore fixed size, variable size, and pattern based solutions at the application layer.
Explore the fixed message size solution for TCP demarcation, buffering in a circular buffer until a 20-byte message accumulates, then extracting and processing it.
Explore a variable-size message scheme for TCP that uses a fixed header to encode total data length, enabling the receiver to extract exact bytes from a circular buffer.
Implement and integrate a byte circular buffer as the core data structure for TCP message demarcation, exposing BCB write and BCB read APIs in C/C++.
Use fixed-size and variable-size marker classes derived from a base tcp message marker to implement tcp message demarcation, exposing virtual functions is buffer ready to flush and process client message.
Implement a base class for the DHCP message marker, with header and cpp files, featuring byte circular buffer, a write circular buffer, constructors, destructor, destroy, and a process message flow.
Implement a derived tcp message class with a fixed-size marker, read fixed-size chunks from a byte circular buffer, and push complete messages to the application for processing.
Integrate the TCP message fixed size demarcation marker into the main project by assigning it to new clients after accept, then process 27-byte messages from the byte circular buffer.
Integrate a clean command-line interface to a growing project using an external CLI library, enabling custom config and runtime control for testing and interaction.
Download the cli library command parser from GitHub, remove the .git folder, adjust its Makefile for g++, update Makefile to link -l command_parser -l cli -lrt and build libcommand_parser.a, recompile.
Extend a CLI by creating config and show commands, building a TCP server name CLI tree, registering command handlers, and invoking back-end logic (config DHCP server name).
Describe how the backend cli handler extracts the user defined server name, creates a tcp server with default ip and port, and plans to support custom ip and port.
Create and manage multiple TCP servers by configuring IP addresses and ports, registering commands, and starting servers for testing with a client.
Explore TCP server states: initialized, running, not accepting new connections, not listening to existing clients, and multithreaded client handling, and learn runtime admin commands to configure the server behavior.
Implement and manage tcp server flags for initialized, running, and not accepting new connections, and expose cli commands to enable or disable connection acceptance via stop and start acceptor services.
Learn to stop the tcp new connection acceptor and the tcp client service manager by implementing stop methods that cancel threads, release the accept file descriptor, and delete the service.
Demonstrates stopping and starting listening for new connections using the stop API and TCP server controller, showing how to stop the accept service, start new connections, and verify client states.
Learn how to suspend listening to already connected clients by implementing a disabled client listen flag, and stop and start the TCP client service manager without closing connections.
Review how the TCP server becomes configurable by clients, with demarcation and CLI start/stop. Explore enabling the server to act as a TCP client to remote servers by implementing connect.
Explore handling concurrency across three threads—the application, css, and drc threads—while safeguarding the central TCP client database with read-write locks, ensuring thread-safe read and write operations.
Master concurrency by implementing a read-write lock for the TCP client database, initializing and destroying the lock, and sandwiching each API operation between the lock and unlock.
Learn to implement a DHCP server as an active opener using the connect system call to initiate a TCP connection and perform the three-way handshake with a server via CLI.
Learn how active and passive openers are created via connect and accept calls, build tcp client objects with ip address and port, and distinguish server and client roles.
Demonstrates connect() by linking two localhost tcp servers (ports 30000 and 35000), showing a client and a server, with dynamic port use, active and passive openers, and retry logic.
Implement a CLI config for a TCP server connection, defining a connect parameter with IP address and port, and create an active client with a retry loop.
Explore joinable and detached threads in POSIX threading: how pthread_create sets mode, how join blocks the parent until the child finishes, and resources are released after join.
Explore how detached threads release resources immediately upon termination and do not return results to joining threads, unlike joinable threads that require joining; learn how converting between states affects behavior.
Explore joinable threads in posix by launching two threads that compute the square of an input, returning results via heap memory and synchronizing with the main thread through join operations.
Explain how pthread_join waits for thread termination, showing that any thread within a process can join any other thread, including parent, child, and grandchild relationships.
Decide to use joinable threads when a thread must return a result or when termination must be notified to other threads, as in MapReduce; otherwise create detached threads.
Welcome to this Course on TCP/IP Socket Programming. Unlike other Courses, this is Advanced Course on Socket Programming. This course assumes that you are already familiar with Socket Programming basics and now want to take it to the next level. This course is about how TCP/IP Socket Programming is deployed in the industry to solve complex networking problems.
We will go beyond simple implementation of client/servers programs present all over the internet ( Advanced Course )
Course objective: Learn how to implement a typical complex Socket based Programs, closely tied to thread management
In this course, we will be going to build the Complete TcpServer Program in which we will cover :
How to manage Multiple Clients through Multiplexing
Notifying events to the application
Client new connection
Client disconnection
Client msg recvd
TCP Message Demarcation
Fixed Message Size Demarcation
Variable Message Size Demarcation
Integrate CLI interface with the Project
Gracefully Shutting down TCP Server
Handling Concurrency using locks
Implementing connect() with retries
< Advanced features to implement >
Creating Multi-Threaded Clients
Forcefully disconnecting the client
Detecting connection live-ness using Keep-Alive msgs
Maintaining statistics per client connection
Client Migration from Multiplexed to Multi-Threaded ( Or Vice Versa )
Building Socket Programming C++ Library over Posix
Pre-requisites :
1. Basic knowledge of TCP/IP Socket Programming through C/C++
2. C/C++ programming ( Intermediate Level )
3. Multi-Threading Basic Concepts ( creating a thread, Cancelling a thread, Producer/Consumer Pattern, Binary and Zero Semaphores )
4. Zeal to learn, explore and do research
5. Linux-based Course, should be done on Linux/MAC-OS only. No Windows Pls.
6. You should have a GitHub account.
This Course is not a :
1. Teaching basic Socket Programming and fundamentals
2. C/C++ programming language tutorial
3. Data Structure or Algorithm Course
4. Multithreading Tutorial
* We don't use any third-party library. Everything is built up from scratch.
* This Course is protected by a full refund policy within 30 days of purchase
* The Emphasis of this course is on Logistics & Concepts, rather than Programming Language. You should be able to do this Course in a programming language of your choice - Java/Python etc.