Network Programming
Module-1
❖ Introduction to network application
❖ client/server communication
❖ OSI Model
❖ BSD Networking history
❖ Test Networks and Hosts
❖ Unix Standards
❖ 64-bit architectures
❖ Transport Layer: TCP, UDP and SCTP
❖ Introduction to network application
A network application is a software program which operates over a network and
allows communication and data sharing between multiple devices and users.
Various essential technologies, often referred to as building blocks, serve as
foundational elements that developers can utilize to create scalable and effective
applications within a networking infrastructure.
There is a wide range of network applications that are used on different devices
like smartphones, tablets, laptops, servers, etc. In fact, every device connected to a
network relies on some form of network application to communicate effectively
within that network.
An Introduction to Network Applications typically covers the fundamental concepts of
how software applications communicate over a computer network. Here's a simplified
overview suitable for an engineering student like you:
🌐 What is a Network Application?
A network application is a software program that runs on a network and uses the
Internet or other networks to communicate with other programs or devices.
Examples:
• Web browsers (e.g., Chrome, Firefox)
• Email clients (e.g., Outlook)
• Messaging apps (e.g., WhatsApp)
• File-sharing tools (e.g., BitTorrent)
Key Components
1. Client-Server Model
o Client: Initiates the communication (e.g., web browser).
o Server: Waits for requests and responds (e.g., web server like Apache).
2. Peer-to-Peer (P2P) Model
o No central server. All nodes (peers) act as both clients and servers (e.g.,
torrent applications).
3. Protocols
o Define rules for communication.
o Common ones include:
▪ HTTP/HTTPS (for websites)
▪ FTP (file transfer)
▪ SMTP/IMAP/POP3 (email)
▪ DNS (domain name lookup)
📶 How Do They Work?
When you open a web page:
1. Your browser (client) sends a request using HTTP to a web server.
2. The server processes the request and sends back the HTML content.
3. The browser displays the web page.
Tools and Technologies Used
• Sockets: Programming interface for sending/receiving data across the network.
• APIs: Interfaces that allow different software systems to communicate.
• Frameworks/Libraries: E.g., Flask (Python), [Link] (JavaScript) for building
network applications.
📌 Why Are They Important?
• Enable global communication (email, chat, video).
• Power most online services (banking, e-commerce, social media).
• Form the backbone of the internet.
Would you like a deeper explanation on any specific topic (like HTTP, DNS, or how sockets
work)?
❖ client/server communication
Client
When we talk about a "Client," it refers to a device (usually a computer, smartphone, or
application) that requests and receives services from a server. The client is the entity that
initiates communication, asking for data or resources from the server. For instance, web
browsers like Google Chrome, Mozilla Firefox, or Safari are common client applications
that request data from a server to render web pages.
Server
A Server, on the other hand, is a remote computer or system that provides data, resources,
or services to clients. It listens to incoming client requests, processes them, and sends the
required information back. A server can handle multiple client requests simultaneously.
For example, Web servers host websites, and database servers store and serve databases for
applications. In simple terms, the client sends a request to the server, and the server serves
the request as long as the data or service is available in its system.
Together, these components, known as Just-In-Time (JIT) Compilers, allow the browser to
convert raw data into a visual webpage.
Advantages of the Client-Server Model
The Client-Server model offers several advantages that make it popular in networked
and distributed systems:
• Centralized Data Management: All data is stored in a centralized server, which
makes it easier to manage, update, and back up.
• Cost Efficiency: Since the server handles most of the processing, clients require
fewer resources and can be simpler devices, reducing costs.
• Scalability: Both clients and servers can be scaled separately. Servers can be
upgraded to handle more clients, and new clients can be added without significant
changes to the server infrastructure.
• Data Recovery: Centralized data storage on the server allows for better data
recovery and easier backup strategies.
• Security: Security measures such as firewalls, encryption, and authentication can be
centralized on the server, ensuring that sensitive data is protected.
Disadvantages of Client-Server Model
• Clients Are Vulnerable: Clients are prone to viruses, Trojans, and worms if present
in the Server or uploaded into the Server.
• Servers Are Targets: Servers are prone to Denial of Service (DOS) attacks, where
the server is overwhelmed with traffic and made unavailable to legitimate clients.
• Data Spoofing and Modification: Data packets may be spoofed or modified during
transmission if the proper security measures (e.g., encryption) are not implemented.
• Man-in-the-Middle (MITM) Attacks: Phishing or capturing login credentials or
other useful information of the user are common and MITM(Man in the
Middle) attacks are common.
❖ OSI Model
A common way to describe the layers in a network is to use the International Organization for
Standardization (ISO) open systems interconnection (OSI) model for computer
communications. This is a seven-layer model, which we show in Figure 1.14 , along with the
approximate mapping to the Internet protocol suite.
Figure 1.14. Layers in OSI model and Internet protocol suite
Sure, here's a simplified explanation of the key ideas from that text:
Understanding Network Layers (Simplified)
The OSI model divides networking into 7 layers, but when writing software, we usually focus
on just the top layers. Here's how it breaks down:
🔧 Lower Layers (Device Driver + Networking Hardware)
• These are built into the system.
• You don’t usually deal with them directly.
• Just one thing to know: Ethernet has a size limit per packet (called MTU), usually
1500 bytes.
🌐 Network Layer
• Managed by IPv4 and IPv6 protocols.
• These take care of sending data between computers.
🔁 Transport Layer
• Two main choices: TCP and UDP.
o TCP: Reliable, ordered, slower.
o UDP: Faster, but no guarantees.
• There’s a thing called a raw socket that lets you skip this layer and use IP directly —
covered later in advanced chapters.
🧠 Application Layer
• Combines the top three OSI layers.
• Examples: Web browsers, FTP servers, Telnet clients.
• In most cases, you don’t worry about the distinction between the three upper OSI
layers.
📞 Sockets
• A socket is a programming tool that lets applications use TCP or UDP to
communicate over the network.
• This book focuses on teaching how to use sockets for writing networked programs.
🧱 Why Sockets Work Between Layers 4 and 5?
1. Separation of roles:
o Application layers know about what the program needs (like FTP or HTTP).
o Lower layers handle sending and receiving data correctly.
2. User process vs. kernel:
o Applications (user processes) use sockets to talk to the network stack, which is
managed by the OS (kernel).
❖ BSD Networking history
The sockets API originated with the 4.2BSD system, released in 1983. Figure 1.15 shows the
development of the various BSD releases, noting the major TCP/IP developments. A few
changes to the sockets API also took place in 1990 with the 4.3BSD Reno release, when the
OSI protocols went into the BSD kernel.
Here’s a simplified explanation of the key points in your text:
How BSD Influenced Modern Networking (Simply Explained)
📜 BSD and Networking Code
• In the 1980s and 1990s, a group at Berkeley (CSRG) worked on a version of Unix
called BSD (Berkeley Software Distribution).
• Their versions included full support for networking — like TCP/IP, sockets, and
apps like Telnet and FTP.
• This networking code was not based on AT&T Unix, so it didn’t have the same legal
restrictions.
🆓 Freely Available Code
• Starting in 1989, Berkeley released the networking parts of BSD as free, public
downloads (even by anonymous FTP).
• The final official versions from Berkeley were:
o 4.4BSD-Lite (1994)
o 4.4BSD-Lite2 (1995)
🧱 Foundation for Other Systems
• These final versions became the base for several modern operating systems,
including:
o FreeBSD
o NetBSD
o OpenBSD
o BSD/OS
• Many of these are still being developed today.
🖥️ Impact on Unix Systems
• Many Unix systems used the Berkeley networking code, especially the sockets API.
• These are called Berkeley-derived implementations.
🏢 Commercial Unix
• Some commercial Unix systems (like UnixWare) also used Berkeley networking.
• Others (like Solaris 2.x) used their own, independently developed networking code.
🐧 What About Linux?
• Linux was created separately.
• It did not use BSD’s code — its networking and sockets were built from scratch.
📌 Summary
BSD was hugely important in making modern networking work the way it does today. Many
systems use its ideas, especially the sockets interface. Even Linux, while independent,
follows similar concepts.
Let me know if you'd like a visual timeline or diagram!
❖ Test Networks and Hosts
Figure 1.16 1.9 Test Networks and Hosts shows the various networks and hosts used in the
examples throughout the text. For each host, we show the OS and the type of hardware (since
some of the operating systems run on more than one type of hardware). The name within
each box is the hostname that appears in the text.
The topology shown in Figure 1.16 is interesting for the sake of our examples, but the
machines are largely spread out across the Internet and the physical topology becomes less
interesting in practice. Instead, virtual private networks (VPNs) or secure shell (SSH)
connections provide connectivity between these machines regardless of where they live
physically.
Figure 1.16. Networks and hosts used for most examples in the
mastery of sockets and other key networking APIs. One book delivers comprehensive, start-
to The notation "/24" indicates the number of consecutive bits starting from the leftmost bit
of the address used to identify the network and subnet. Section A.4 finish guidance for
building robust, high-performance networked systems in any environment: will talk about the
/n notation used today to designate subnet boundaries. UNIX Network
ing on the legendary work of W. Richard Stevens, this edition has been fully updated by The
real name of the Sun OS is SunOS 5.x and not Solaris 2.x, but everyone refers to it as Solaris,
the name given to the sum of the OS and other software bundled with the base OS.
❖ Unix Standards
Overview
In today’s diverse computing environments, a strong operating system (OS) foundation is
needed to drive business continuity and scalability. UNIX®, an open standard owned and
managed by The Open Group, is an enabler of key technologies and delivers reduced total
cost of ownership, increased IT agility, stability, and interoperability in hetero¬geneous
environments enabling business and market innovation across the globe. This OS has an
interesting history while showcasing a robust modern market momentum. Download the
UNIX Overview Brief today.
UNIX: An Innovative History
The history of computing would not be complete without the vision of Ken Thompson and
Dennis Ritchie. Both men couldn’t have anticipated the impact of their contribution to the IT
industry in 1969. Thompson, Ritchie, and others at Bell Labs created a collaborative
programming environment that would promote what is now commonly called “open
development”.
The success of the UNIX approach led to a large number of “look-alike” operating systems,
often divergent in compatibility and interoperability. To address this, vendors and users
joined together in the 1980s to create the POSIX® standard and later the Single UNIX
Specification. Formal UNIX certification started in 1995, with all the major UNIX vendors
certifying their products. Most recently, a Linux® distribution has become UNIX certified
continuing the trend and value of basing operating systems on the UNIX standard. Download
the UNIX Evolution Infographic to get more information.
UNIX: Driving Innovation Today
The UNIX OS plays a big role in the current market landscape and is an enabler of
technologies such as cloud computing, security, virtualization, mobility, and more. It has a
proven track record of adoption by Global 100 and Fortune 100 companies. The UNIX OS is
a strong choice for verticals such as telecommunications, manufacturing, pharmaceuticals,
financial services, government, healthcare, defense, and more. For these end-user enterprises,
procuring certified UNIX systems and software ensures the highest level of availability,
scalability, and maintainability for those who want to focus on their business with confidence
and peace of mind without the worry of disruption in their global IT environments.
Single UNIX Specification- “The Standard”
The Single UNIX Specification is the standard in which the core interfaces of a UNIX OS are
measured. The UNIX standard includes a rich feature set, and its core volumes are
simultaneously the IEEE Portable Operating System Interface (POSIX) standard and the
ISO/IEC 9945 standard. The specification encompasses the base operating system
environment, networking services, windowing system services, and internationalization
aspects and programming languages. The latest version of the certification standard is UNIX
V7, aligned with the Single UNIX Specification Version 4, 2018 Edition. Read or download
the Single UNIX Specification here.
UNIX Open Standards Development
The Open Group Governing Board UNIX Systems Work Group sets the strategy and
influences the direction for the evolution of the Single UNIX Specification. The Work Group
is comprised of The Open Group Platinum Members, all industry leaders each with a
representative on The Open Group Governing Board. A few examples of UNIX based
operating systems are IBM® AIX®, HPE™ HP-UX®, Oracle® Solaris®, and Inspur® K-
UX.
Certification of Conformance to the Standard
The Open Group grants licenses through the UNIX Certification Program. Suppliers are
granted a license to use the UNIX trademark in connection with a product when:
The product has demonstrated passing the applicable certification test suites.
The supplier has formally agreed to the terms of the Certification Program.
An Open Brand Certificate is issued for each Registered Product that has been certified
against the standard. An entry is made in the Directory of Registered Products, which can be
found on The Open Group website at [Link]/openbrand/register.
Read details on the UNIX certification.
❖ 64-Bit Architectures
Back in the mid to late 1990s, computer systems started using 64-bit technology.
Why? Because 64-bit systems can handle much more memory than 32-bit systems. Think of
memory like a giant library — 32-bit systems can only keep track of so many books (memory
addresses), while 64-bit systems can keep track of an enormously bigger library.
About the programming models:
• In 32-bit systems, there’s a common way of storing numbers and addresses called
ILP32. This means:
o I (integers),
o L (long integers), and
o P (pointers, which are like addresses in memory)
are all stored in 32 bits (which is 4 bytes).
• In 64-bit systems, there’s a popular model called LP64. This means:
o L (long integers) and
o P (pointers)
are stored in 64 bits (8 bytes),
but I (integers) stay 32 bits (4 bytes).
Why does this matter?
• Using 64 bits for pointers means the computer can handle way more memory, which
is great for big programs or databases.
• Keeping integers at 32 bits helps with compatibility and efficiency because most
numbers programmers use don’t need 64 bits.
So, the shift to 64-bit computing meant a change in how data types like pointers and numbers
are stored in memory, to better handle larger amounts of memory without wasting space
unnecessarily.
Figure 1.17. Comparison of number of bits to hold various datatypes for the ILP32 and LP64
models.
🔢 32-bit vs. 64-bit Systems — The Programming Impact
When we move from 32-bit to 64-bit systems, it’s like going from a small apartment to a
huge house. You have more space (more memory), but you also need bigger keys (pointers)
to unlock that space.
In programming, this shift brings some important changes, especially in how data sizes are
handled.
👨💻 What’s the LP64 Model?
In 64-bit Unix systems, most systems use the LP64 model:
• L (long) and P (pointers) are 64 bits (8 bytes)
• I (int) stays 32 bits (4 bytes)
This means:
• You can’t assume a pointer will fit into an int anymore — it’s too big!
• Old code that does things like storing pointers in int variables might break.
📦 What is size_t?
• size_t is a special type used to represent sizes — like how much memory you want
to allocate, or how many bytes to read/write.
• On a 32-bit system: size_t is 32 bits
• On a 64-bit system: size_t is 64 bits — so you can work with large amounts of data
Example:
c
CopyEdit
malloc(1000); // Uses size_t to know how many bytes to allocate
So size_t grows in size to match the new, bigger memory model.
API Compatibility Issues
Some older APIs made bad choices:
• They used long or size_t for things like the size of a socket address, even though:
o A socket address is only a few hundred bytes — it doesn’t need 64 bits
o Using 64 bits would break programs built on 32-bit systems
The Fix: Use Special Datatypes
To avoid breaking old programs and to keep things efficient, programmers introduced new,
more precise types:
Use Case New Type
Use Case New Type
Socket address sizes socklen_t
XTI structure fields t_scalar_t, t_uscalar_t
These types are designed to stay 32 bits even on 64-bit systems — because they don’t need to
be bigger. This helps keep binary compatibility with older 32-bit applications.
❖ Transport Layer: TCP, UDP and SCTP
The transport layer is the fourth layer in the OSI model and the second layer in the TCP/IP
model. The transport layer provides with end to end connection between the source and the
destination and reliable delivery of the services. Therefore transport layer is known as the
end-to-end layer. The transport layer takes the services from its upward layer which is the
application layer and provides it to the network layer. Segment is the unit of data
encapsulation at the transport layer.
In this article, we are going to discuss all the important aspects of Transport Layer Protocol
which include: Functions of Transport Layer protocol, characteristics of TLP, UDP & UDP
Segemnts and their Advantages and Disadvantages, TCP & TCP Segemnts and their
Advantages and Disadvantages, SCTP and its Advantages & Disadvantages.
Functions of Transport Layer
• The process to process delivery
• End-to-end connection between devices
• Multiplexing and Demultiplexing
• Data integrity and error Correction
• Congestion Control
• Flow Control
Characteristics of Transport Layer Protocol
• The two protocols that make up the transport layer are TCP and UDP.
• A datagram is sent by the IP protocol at the network layer from a source host to a
destination host.
• These days, an operating system can support environments with multiple users and
processes; a programme under execution is referred to as a process.
• A source process is transmitting a process to a destination process when a host sends a
message to another host. Certain connections to certain ports, referred to as protocol
ports, are defined by the transport layer protocols.
• A positive integer address, consisting of 16 bits, defines each port.
Transport Layer Protocols
The transport layer is represented majorly by TCP and UDP protocols. Today almost all
operating systems support multiprocessing multi-user environments. This transport layer
protocol provides connections to the individual ports. These ports are known as protocol
ports. Transport layer protocols work above the IP protocols and deliver the data packets
from IP serves to destination port and from the originating port to destination IP services.
Below are the protocols used at the transport layer.
1. UDP
UDP stands for User Datagram Protocol. User Datagram Protocol provides a nonsequential
transmission of data. It is a connectionless transport protocol. UDP protocol is used in
applications where the speed and size of data transmitted is considered as more important
than the security and reliability. User Datagram is defined as a packet produced by User
Datagram Protocol. UDP protocol adds checksum error control, transport level addresses, and
information of length to the data received from the layer above it. Services provided by User
Datagram Protocol(UDP) are connectionless service, faster delivery of messages, checksum,
and process-to-process communication.
UDP Segment
While the TCP header can range from 20 to 60 bytes, the UDP header is a fixed, basic 8
bytes. All required header information is contained in the first 8 bytes, with data making up
the remaining portion. Because UDP port number fields are 16 bits long, the range of
possible port numbers is defined as 0 to 65535, with port 0 being reserved.
UDP
• Source Port: Source Port is a 2 Byte long field used to identify the port number of
the source.
• Destination Port: This 2-byte element is used to specify the packet's destination port.
• Length: The whole length of a UDP packet, including the data and header. The field
has sixteen bits.
• Cheksum: The checksum field is two bytes long. The data is padded with zero octets
at the end (if needed) to create a multiple of two octets. It is the 16-bit one's
complement of the one's complement sum of the UDP header, the pseudo-header
containing information from the IP header, and the data.
Advantages of UDP
• UDP also provides multicast and broadcast transmission of data.
• UDP protocol is preferred more for small transactions such as DNS lookup.
• It is a connectionless protocol, therefore there is no compulsion to have a connection-
oriented network.
• UDP provides fast delivery of messages.
Disadvantages of UDP
• In UDP protocol there is no guarantee that the packet is delivered.
• UDP protocol suffers from worse packet loss.
• UDP protocol has no congestion control mechanism.
• UDP protocol does not provide the sequential transmission of data.
2. TCP
TCP stands for Transmission Control Protocol. TCP protocol provides transport layer
services to applications. TCP protocol is a connection-oriented protocol. A secured
connection is being established between the sender and the receiver. For a generation of a
secured connection, a virtual circuit is generated between the sender and the receiver. The
data transmitted by TCP protocol is in the form of continuous byte streams. A unique
sequence number is assigned to each byte. With the help of this unique number, a positive
acknowledgment is received from receipt. If the acknowledgment is not received within a
specific period the data is retransmitted to the specified destination.
TCP Segment
A TCP segment's header may have 20–60 bytes. The options take about 40 bytes. A header
consists of 20 bytes by default, although it can contain up to 60 bytes.
• Source Port Address: The port address of the programme sending the data segment
is stored in the 16-bit field known as the source port address.
• Destination Port Address: The port address of the application running on the host
receiving the data segment is stored in the destination port address, a 16-bit field.
• Sequence Number: The sequence number, or the byte number of the first byte sent in
that specific segment, is stored in a 32-bit field. At the receiving end, it is used to put
the message back together once it has been received out of sequence.
• Acknowledgement Number : The acknowledgement number, or the byte number
that the recipient anticipates receiving next, is stored in a 32-bit field called the
acknowledgement number. It serves as a confirmation that the earlier bytes were
successfully received.
• Header Length (HLEN): This 4-bit field stores the number of 4-byte words in the
TCP header, indicating how long the header is. For example, if the header is 20 bytes
(the minimum length of the TCP header), this field will store 5 because 5 x 4 = 20,
and if the header is 60 bytes (the maximum length), it will store 15 because 15 x 4 =
60. As a result, this field's value is always between 5 and 15.
• Control flags: These are six 1-bit control bits that regulate flow control, method of
transfer, connection abortion, termination, and establishment. They serve the
following purposes:
o Urgent: This pointer is legitimate
o ACK: The acknowledgement number (used in cumulative acknowledgement
cases) is valid.
o PSH: Push request
o RST: Restart the link.
o SYN: Sequence number synchronisation
o FIN: Cut off the communication
o Window size: This parameter provides the sender TCP's window size in
bytes.
• Checksum: The checksum for error control is stored in this field. Unlike UDP, it is
required for TCP.
• Urgent pointer: This field is used to point to data that must urgently reach the
receiving process as soon as possible. It is only valid if the URG control flag is set. To
obtain the byte number of the final urgent byte, the value of this field is appended to
the sequence number.
Advantages of TCP
• TCP supports multiple routing protocols.
• TCP protocol operates independently of that of the operating system.
• TCP protocol provides the features of error control and flow control.
• TCP provides a connection-oriented protocol and provides the delivery of data.
Disadvantages of TCP
• TCP protocol cannot be used for broadcast or multicast transmission.
• TCP protocol has no block boundaries.
• No clear separation is being offered by TCP protocol between its interface, services,
and protocols.
• In TCP/IP replacement of protocol is difficult.
3. SCTP
SCTP stands for Stream Control Transmission Protocol. SCTP is a connection-oriented
protocol. Stream Control Transmission Protocol transmits the data from sender to receiver in
full duplex mode. SCTP is a unicast protocol that provides with point to point-to-point
connection and uses different hosts for reaching the destination. SCTP protocol provides a
simpler way to build a connection over a wireless network. SCTP protocol provides a reliable
transmission of data. SCTP provides a reliable and easier telephone conversation over the
internet. SCTP protocol supports the feature of multihoming ie. it can establish more than one
connection path between the two points of communication and does not depend on the IP
layer. SCTP protocol also ensures security by not allowing the half-open connections.
Advantages of SCTP
• SCTP provides a full duplex connection. It can send and receive the data
simultaneously.
• SCTP protocol possesses the properties of both TCP and UDP protocol.
• SCTP protocol does not depend on the IP layer.
• SCTP is a secure protocol.
Disadvantages of SCTP
• To handle multiple streams simultaneously the applications need to be modified
accordingly.
• The transport stack on the node needs to be changed for the SCTP protocol.
• Modification is required in applications if SCTP is used instead of TCP or UDP
protocol.