0% found this document useful (0 votes)
2 views20 pages

Introduction To Network Programming

The document provides an introduction to network programming, detailing how computers communicate over networks through protocols and the client-server model. It covers socket programming basics, including the creation and binding of sockets, as well as data transmission methods using TCP and UDP. Additionally, it discusses the architecture of client-server systems and the processes involved in sending and receiving data across networks.

Uploaded by

Asimobi Nnaemeka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views20 pages

Introduction To Network Programming

The document provides an introduction to network programming, detailing how computers communicate over networks through protocols and the client-server model. It covers socket programming basics, including the creation and binding of sockets, as well as data transmission methods using TCP and UDP. Additionally, it discusses the architecture of client-server systems and the processes involved in sending and receiving data across networks.

Uploaded by

Asimobi Nnaemeka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Introduction to Network Programming

1. Overview of Network Programming


Network programming allows computers to exchange data. It is the way a computer
communicates with other computers over a network, such as the Internet or a Local
Area Network. It defines rules to be followed by the computers that are
communicating. A program on one computer can send some data to a program on
another computer. It allows the transfer of files between the computers.

Communication between the computers can be either connection-oriented or


connectionless. Connection-oriented communication involves the establishment of a
connection between the computers before the transmission of data. The computers
have to follow a multiple-step process for establishing a connection before
communicating. Connectionless communication does not require a connection to be
established. The destination computer must be specified while sending the data.
Data segments are independent of each other. If a data segment is lost, it is lost
permanently.

2. Network Protocols
Often described as the "language" that machines use to communicate over the
Internet, a network protocol defines the format and the ordering of messages sent
and received among network-connected devices, as well as the actions taken on the
transmission and receipt of a message or other event. The Internet architecture
employs a suite of protocols at different layers on each machine that together
implement the network services for applications, enabling applications on different
hosts to engage in communication.

Client-server model. When machines communicate, it is often the case that one
machine initiates the dialogue by sending a request for service, and the other
machine responds accordingly. In such cases, the requesting machine is termed the
client, and the responding machine is called the server. For example, when a
browser requests a Web document, it communicates with the Web server that is
serving the document. In this client-server model, the application-level protocol
defines the messages that are exchanged between the client and the server to
implement the particular service.
2.1. TCP/IP Model
The TCP/IP model, a set of communications protocols used for the Internet and
other similar networks, is implemented practically everywhere. This model was
originally developed following an initial implementation of the protocol suite in the
UNIX operating system, and current versions of UNIX (and all Linux distributions)
natively support the protocols as standard tools. We imagine that a host has an
application; for example, a Web server is accepting inbound Internet connection
requests. Supposed the operating-system kernel supports TCP/IP, then these
facilities must command and control the hardware to send and receive packets at
the data-link layer and to react intelligently to events such as an incoming Web
request, an attempt to connect to a locally non-existent port, or a failure to get a
packet acknowledged.

Assuming that a TCP/IP stack is implemented by a layer within the operating


system, the logical-socket model for communication is as follows: an application
uses the operating system's socket calls to ask that the host listen on port number
80 for incoming connections (or, more mundanely, to send some bytes to a different
host on the network). Some other part of the kernel then moves these packets to
and from the hardware and also implements error control and retransmission. In
the receive direction, a socket pair uniquely identifies a connection; in the transmit
direction, the system deduces the contents of the socket pair from the arguments
passed into the socket call and the local host's names and addresses.

2.2. UDP Protocol


The User Datagram Protocol (UDP) is a simple transmission model without implicit
connectivity (Ionuţ Andreica et al., 2012). It provides a fast method to transmit data.
One of the features of UDP is multicast addressing. The protocol is implemented
entirely in user space. UDP is chosen as the basis for the protocol because of its
simple, performance-oriented design, and it offers the functionality of multicast
with the reliability of TCP, as well as other forms of one-to-many addressing.

2.3. Application Layer Protocols


Together with the transport layer discussed in the previous section, the application
layer completes the transport service offered to network applications. This
application-layer functionality is typically implemented in a user program that
establishes communication between two interacting processes. Common examples
of Internet client-server applications that provide such communication are Telnet,
FTP, SMTP, and the World Wide Web (WWW).

The overall Internet interprocess communication service can be organized into


several layered models that, at one extreme, do everything in the kernel and, at the
other, do everything in user code. For instance, UNIX sockets provide a rudimentary
transport service, enabling connected processes to exchange data via write and read
operations. Higher-level communication can be built on top of this, such as line-
based communication, RLOGIN, and RPC. These mechanisms are typically
implemented as libraries, and applications link to the appropriate library depending
on the communication style required.

Programming interface styles mirror these layered models, allowing application


designers to choose the appropriate behavior (Ionuţ Andreica et al., 2012).

3. Socket Programming Basics


Socket programming provides the basis for connecting computers on the Internet
and reading and writing information over those connections. Socket programming is
a form of interprocess communication over a network. It is usually done over an IP
network using the Transmission Control Protocol (TCP) or User Datagram Protocol
(UDP) sockets. For this reason, it is popularly called TCP/IP or UDP/IP socket
programming.

Socket-oriented programming is very different from object-oriented programming


in C++ and Java. In socket programming, a process will act as a server, a client, or as
both at the same time. Consider two processes or computers, P1 and P2. A process
can be implemented to provide services to the other process over the network; that
process is called a server. The other process, which requests information from the
other, is called a client. The client asks for a particular service from the server, and
the server provides services to the client. When the server and the client
communicate over the Internet, they send packets of data with the destination
address and port number of the destination process.

3.1. What are Sockets?


A socket is a software communication mechanism that enables message exchanges
between software processes, which may reside on the same computer or on
different interconnected computers. As a conceptual communication endpoint, a
socket is associated with a particular transport address and a local port number, the
socket address.

Sockets have been the fundamental building blocks of Internet operations since the
inception of the Internet protocol suite, which includes both TCP and UDP. The TCP
API was proposed around 1980 by Berkeley and remains the main API of all current
implementations of the Internet protocol suite today.
3.2. Creating a Socket
A client or server must communicate using a socket to implement TCP
communication. Before data exchange can occur, it is necessary to create a socket.
This request is passed to the operating system via a function call. The code below
creates a socket descriptor socket_fd in the client process. The first parameter
defines the family of protocols. The second parameter represents the requirements
of the socket type. SOCK_STREAM marks a connection-oriented socket. When
SOCK_DGRAM is specified, a connectionless socket is created.

3.3. Binding a Socket


Before a socket can be used by an application program, it has to be assigned a name.
This assignment process is called binding a socket. The function used is int bind (int
sockfd, struct sockaddr* myaddr, int addrlen); A socket can be advertised over a
network as an end-point. A server, for example, would advertise its sockets
routinely so that the client knows where to establish a connection. Binding occurs
when these sockets are given a name. Usually, an IP address is used as the socket
name. The name given to a socket always consists of the socket family, the port
number, and the IP address. The three elements have different meanings, described
in the next section.

The function call to bind is shown below. sockfd is the socket handle returned by
socket. myaddr is the name to be given to the socket; it is a pointer to a struct
sockaddr var. addrlen is the length of the struct sockaddr structure. With an
AF_INET socket, myaddr is actually a pointer to a struct sockaddr_in. Consequently,
casting is needed (address family, port, and IP address). Before bind can be called,
the programmer must generate these three bindings within a struct sockaddr_in
variable.

4. Client-Server Architecture
Client-server architecture forms the basis for numerous network applications,
ranging from those with substantial processing logic residing on servers—such as
database servers and web servers—to those with extensive processing conducted
on client machines, exemplified by web browsers. This paradigm is foundational to
peer-to-peer technology but differs in that peer-to-peer systems distribute
processing across all machines in the network, rather than concentrating it in a
singular server entity.

A classic illustration of client-server interaction can be observed in a typical web


transaction: the client (web browser) dispatches a request for a Web Object—for
instance, a file named index.html—and the server replies by delivering the
requested content. Scripted languages allow Web Pages themselves to function as
Web Servers, generating dynamic content based on input values received from
clients.

In the course “Vanilla TCP,” a rudimentary file transfer process serving as a


dependable transport protocol is delineated, augmented by a GUI component.
Implemented in the Java programming language, this context showcases file transfer
between server and client nodes situated within the same local area network.
Neither node maintains an awareness of the other’s presence, emphasizing the
spontaneous establishment of a dependable, end-to-end communication channel
upon the arrival of data packets at the Transport Layer. This dynamic connection
formation persists under the supervision of transport-layer mechanisms exerting
strict control over the transmission process (Bukhowa, 2018).

The “Bookstore Enquiry” application exemplifies TCP client-server programming:


the server, a singleton class, houses information about books and perpetually awaits
client requests via a server socket bound to a local address and fixed port. Should a
client request a non-existent book, the server issues an error message and
terminates the connection. Conversely, if the book is found, the client is prompted to
specify the desired information—such as edition and stock availability—which the
server then provides. The employment of TCP guarantees reliable message delivery.

4.1. Understanding Client-Server Model


The client-server interaction model is a fundamental concept underlying network
operations and programs, arranging the work so that one („server“) program listens
to requests, and others („clients“) make a series of requests. The client-server model
is exemplified on the Web: user requests for HTML pages result in the transmission
of these pages, much as a request to a file server results in the transmission of a file.
Browsers or HTTP clients act as clients, contacting the Web server – specified by a
domain name – and requesting a page. The file server reads the specified file and
sends it to the client. Clients and servers running as separate processes, often on
separate machines, communicate with each other using sockets.

Time-sharing systems permit several users to work simultaneously. Ritchie's and


Thompson's UNIX design created a convenient environment for multitasking. One
task can listen for requests from others, and upon receipt of a request, can perform
the requested work. By multiplexing various work, the system can be more
productive than if tasks worked alone.

The model is also used in interactive games and in the control of network
management.
4.2. Building a Simple Client
In Chapter 3, a multi-threaded TCP echo server was developed that accepts
connections from multiple clients and performs the echoing operation for each
client concurrently. In this chapter, the focus shifts to developing a multi-threaded
TCP echo client and a simple TCP echo client.

Unlike the server, which is associated with a well-known server port and is designed
to accept connections from any client, a client does not need to have a well-known
client port because it selects an ephemeral port for each connection. Thus, a client
can make a connection from one of the many available ephemeral ports. The client
port of the TCP connection will be that ephemeral port, while the server port of the
TCP connection will be the well-known port of the server. An echo client is
constructed in a simple way by having the client send a sequence of messages. Each
message that the client sends is then returned by the server and the echo. The client
waits for the echo before sending the next message. This procedure repeats for a
pre-defined number of messages.

4.3. Building a Simple Server


A server is a system program that provides services to other systems by listening for
request messages from peers. When a request message arrives, the server returns a
reply in the form of a response message; this round-trip exchange is called a
transaction. Services run on well-known ports so that clients can easily find them. In
client/server communications, the client always initiates a transaction by sending a
request message to the server. The serviceInstance method opens a listening TCP
socket on port 7, waits until a remote client “connects” to the socket, and returns
when a peer establishes an association with the service port. If no peer ever
connects, the method waits for a very long time—blocking the thread of execution.
The serviceInstance method is called from the main function to create a thread for
each client connection. Although the example illustrates handling multithreaded
clients, practice with threads is delayed until Chapter 6.

A simple server application builds communication services into a program that can
query other hosts for services. The HostServices method provides information
about ports on a host and probes the targetHost to find other services that are
active. When the Client Services method is executed with the local host parameter, it
displays a listing of services running on the local machine. The servicesList method
looks up a service name and returns the port number for the associated service. The
serviceRunnable function calls stoppingAt to obtain a port number, then calls
serviceInstance in a new thread. The Server Runnable sets the localServer socket,
and unless it receives an error, a thread is launched to listen for client connections.
5. Data Transmission
In most networks information is distributed via data streams, composed of a
succession of information units. An information unit in a data network is generally
called a packet, a frame, or a cell, depending on its structure and on the layer
operating in the node and the end-systems. The terms packet switching and packet
forwarding refer to the technique employed by the nodes whereby they route the
packets to the right destination address using the information contained in the
packets themselves.

Generally, the set of layers associated with a switching technique is referred to as a


packet-switching network, regardless of the fact that the underlying technique is
datagram or virtual circuit switching. The terms packet relay and packet
transmission simply indicate the transfer of information via a succession of packets
from a source to a destination.

Information units in a virtual circuit environment have different names depending


on the protocol layer.

5.1. Sending Data


Sending data through a network is a major part of network programming. Sending
data is done in three parts. The first part is provided services and must be done
before the second and third parts. The second part is creating a socket and
connecting to the other side. The third part, after the socket has been created and a
connection established, is to send the data.

An example illustrates the implementation of the third part, sending data with TCP.
Services are provided in the getServByName function or the user can provide the
port and protocol, as in the getServByPort function. After a connection request has
been created with getPeerAddr and the socket descriptor returned by getSocket, the
data can be sent with the sendData function.

5.2. Receiving Data


The client receives data by first filling in a struct sockaddr_in structure with the IP
address and port number of the local machine. It then calls bind, passing the local
sockaddr_in structure, the socket descriptor, the size of the sockaddr_in structure,
and a direction flag telling that the socket is a receiver. After that, the client uses the
socket descriptor, a pointer to a buffer, and the buffer size as the parameter list of
the recvfrom function. The recvfrom function waits for arriving data and copies it to
the buffer. The from flags accept the IP address and port number of the sender. The
recvfrom function returns the number of bytes copied to the buffer.
The sender sends the data by first filling in a struct sockaddr_in structure with the
IP address and port number of the remote machine. It then calls bind, passing the
remote sockaddr_in structure, the socket descriptor, the size of the sockaddr_in
structure, and a direction flag telling that the socket is a sender. After that, the
sender uses the socket descriptor, the buffer, the number of bytes, and a pointer to
the sockaddr_in structure as the parameter list of the sendto function. The sendto
function sends the data.

5.3. Handling Data Streams


Rather than requiring that all of the data from one program be sent in one operation
and all from the other program be received in a single operation, TCP is TCP for a
reason: It provides a stream of bytes between the programs. Data written on one
end will be delivered to the other program in the same order but may be received in
different-sized chunks. In fact, the amount of data received with one read operation
can be larger or smaller than the amount of data sent in one write.

Unix pipes provide a very similar stream of data between processes. The number of
bytes read at one time from a stream can be different from the number of bytes
written at one time to the stream. When using TCP, it is important that dealing with
the stream of bytes also be incorporated into the client-server application.

6. Error Handling in Network Programming


Presented here are a few important TCP socket programming pitfalls, with a focus
on error handling. Developing robust network applications requires continuous
attention to such issues.

Consider a typical testing scenario that involves remote operation of a light meter.
The client connects to the server, collects and transmits an image, receives it back,
disconnects, and finally terminates. This context is exemplary for the issues
described next.

Global errno variables are set whenever system calls and library functions
encounter problems. After the call, the error code value can be printed directly, and
displayed using perror() or even strerror() to obtain a user-friendly error message.
However, some calls return -1 merely to signal congestion or invalid operation; in
this case, it is not an error.

6.1. Common Errors


Every program has errors since it is very difficult to write a correct program. During
network programming, many errors can occur but there is one category of errors
that is unique to network programming—probably because it is difficult to find and
test such errors. Students usually make these errors, and professors also often make
them when writing network programs. The following list identifies those common
or typical errors. The errors are divided into two categories: errors with the
program and errors with the networking concepts.

— Forgetting to allocate space for the long name of a node during conversion of a
short name to a long name. — Trying to use the address family family of the client
directly at the client side. The socket function requires the address family of the
server at the client side. — Confusing the concept of short domain name and long
domain name (IP address). Usually, the short domain name of the client is printed at
the client but this never works because the client itself is not aware of its own short
name. Also, when trying to print the "long name" of any network element, the long
name of the client will be printed if the first argument in the dot notation is zero (0).
If the first argument is nonzero, then the long name of the server will be printed
irrespective of whether the function is called from the client or the server.

6.2. Exception Handling


Exception handling in DCE is similar to that of C++ with one difference. The C++
catch clause takes the class of the exception as its argument and filters the exception
of the same class from the thrown exceptions. In DCE, the exceptions are filtered
through their status codes, which are returned by the system. The exception handler
matches the status code and then handles the exception. DCE uses the _cma_e_
symbol, which is the base number of the CMA topics, to generate the exception list.

The DCE programming language exception handling model also resembles that of
Ada, which makes programming in Ada especially useful when using the UNIX DCE
module.

7. Advanced Socket Programming


By now, the basic workings of sockets, socket addresses and IP addresses should be
understood. This section will cover more advanced socket techniques such as
reading/writing with timeouts, cancellation, IPv4 and IPv6 houses and how to
create a network device on your system and write into it. HTTPS — that famous S in
HTTP — is implemented using a protocol called TLS (Transport Layer Security), or
with its predecessor SSL (Secure Sockets Layer). Both protocols enable encrypted
communication between a client and a server, and ensure that the parties are who
they say they are. On the client side, these protocols are most easily used by creating
a socket then associating a client TLS or SSL context with that socket. You can then
read and write on the socket, and all data will be encrypted and decrypted
automatically. Further discussion of HTTPS is beyond the scope of this introduction,
but the reader is encouraged to explore it.

7.1. Non-blocking Sockets


Socket implementations often provide states and operations for non-blocking
sockets; these functions are called with the socket set into non-blocking mode. In
non-blocking mode, calls to read data() return sooner, in fact they might return
immediately even if no data can be read at all, or calls to write data() might return
sooner (after only writing a part of the data), even if not all data could be written.
For example, if a client uses a socket to write data() but the client is not ready to
receive data, a blocking socket causes the call to pause the client until the server is
ready, even if this takes days. A non-blocking write data() call returns immediately
with an exception indicating that the action cannot be performed now.

In case of a non-blocking connect(), a new socket descriptor is created, but the


connection is not yet ready to be used for communication. The socket can be
registered with a selector and eventually the result of the connection attempt is
obtained with another call to connect(). A non-blocking accept() call returns
immediately: If there are no waiting connections, it returns with an exception (not
blocking the thread). If there is a waiting connection, it returns the descriptor used
to communicate with the new client.

7.2. Multithreading in Socket Programming


The availability of multithreading in modern operating systems allows applications
to implement this feature for specific services. When a web server app receives a
new client request, it typically creates a new thread to manage communication with
that client. This design ensures continuous support for simultaneous HTTP requests
from other clients. Multithreaded operation also enhances performance, as various
activities can be executed concurrently. For example, threads perform accept
operations on different listening Sockets concurrently.

An application task can also create threads to implement simultaneous processing


in socket programs. For instance, a client console app requesting a file from a server
creates two threads upon start-up: one to receive the file contents from the server
and another to save those contents on the client machine. A single-threaded app
cannot execute these two activities concurrently; it must either save received bytes
before retrieving more from the server or receive all contents before initiating the
saving operation. In contrast, a multithreaded app starts both operations
simultaneously, ensuring that while one thread receives file contents, the other
saves already received data to the disk.
8. Network Security
Network security is a supporting service that ensures the delivery of data
transmitted between two entities rather than just making the network available.
The importance of network and communications security has become a notable
concern in recent years. Ongoing evolution of Web and telecommunication
technologies due to ubiquitous access, mobile connectivity, public availability, and
social media have also highlighted the sensitivity of data and personal privacy.
Social media, for example, has contributed extensively to personal and professional
disclosures beyond the intended domains of privacy, where the creation and
appropriation of online identities based on personal data can be used as a weapon
for blackmail or even political instability. Algorithms for network and
communication security often combine methods from cryptography, machine
learning, and statistics for different applications, such as network intrusion
detection, malware detection, spam filtering, and identifying the use of silk road, to
name just a few. Services include authentication, authorization, data confidentiality,
data integrity, and nonrepudiation. To make communication secure, there may be a
need to provide one or more of these services for data exchanged either for specific
messages or an entire connection without affecting the overhead and background
traffic considerably. Cryptography is the major technique that can be used for this
purpose. Furthermore, information security is essential for the defense of nations
and enterprises worldwide. Cryptography and network security have become the
most demanding and challenging areas to develop more advanced and efficient
models to provide a more secure and affordable environment (El-Alfy, 2007)
(Mohammed Khan et al., 2013).

8.1. Introduction to Network Security


Security is the most important feature when it comes to the network. It must be
provided to any network or information system for unauthorized access. An
individual or organization will suffer the loss of data and money if security is not
provided. The aim of network security is to prevent the unauthorized access,
misuse/modification, or denial of a computer network and network-accessible
resources. Network security suites typically consist of multiple layers of
subcomponents, such as an intrusion detection system (IDS) for malware
monitoring, a firewall for network-level border control, and VPN for secure remote
access. Numerous activities like emotional software, human-computer interaction,
and games use communication through the network. At the other end when the data
is going through the network, the security must be there to fulfill the requirements.

Therefore, the need of providing security to the each and every flow of data
highlighted the field of network security. Several cryptographic algorithms are being
used for the securing data in several communication systems from last few years.
The field of network security is similarly never-ending field and still newer and
stronger algorithms are being proposed by the cryptographers (Mohammed Khan et
al., 2013).

8.2. Secure Sockets Layer (SSL)


Secure Sockets Layer (SSL) is a protocol used to achieve secure transactions on the
Internet. SSL provides encryption, data integrity, and authentication to protect
sensitive information during transmission (Klinefelter, 1997).

9. Network Programming in Different Languages


Instructions and explanations for UDP, TCP stream, and TCP socket clients using
both the C and Python programming languages are provided. The aim is to discover
how much of Network Programming can be carried out using Python. While Python
does not allow manipulation of low-level packet headers in the way C does, it
remains a powerful language for socket programming.

Sockets provide a way for Python to connect to a Unix host. Python programmers
can implement the socket interface in a Python application. In–depth knowledge
about the Python socket interface can be gained by reading the online
documentation for the socket module. The socket module provides access to the
BSD socket interface for communicating over the network. The socket module
supports socket operations.

9.1. Python Networking


Modern computer networks define a standard for data exchange using network
protocols, which are hierarchical and standardized interacting methods for data
exchange within two networks. The Transmission Control Protocol/Internet
Protocol (TCP/IP) is the standard network protocol that handles high-level data
exchange in all types of networks, such as the internet and local networks (LAN).
TCP/IP also defines IP addresses and other addressing systems.

The Python language supports low-level network programming through the socket
interface, which supports requests and responses in connection-oriented and
connectionless styles. It also supports email protocols such as SMTP, POP, and IMAP,
browser protocols such as HTTP, FTP, FTPS, and HTTPs, DNS support, and low-level
network features like accessing and manipulating the routing table. Most of these
are implemented as modules distributed with the Python standard library. The
socket module provides low-level support for connection-oriented and
connectionless network protocols.
9.2. Java Networking
The Java platform offers an extensive set of libraries that enable the creation of
robust client-server applications. Classes for implementing client-server
applications are found in packages such as java.net, java.io, java.rmi, javax.net, and
javax.rmi. The java.net package includes classes for both stream-oriented and
datagram-oriented network communication. Classes in javax.net and javax.rmi
support multicast and secure connections, while those in java.rmi package facilitate
remote method invocation on remote objects, invoking methods on server objects.

The Socket class provides support for both stream-oriented socket communication
using TCP and datagram-oriented communication sockets using UDP. Associated
with Socket is the ServerSocket class, which is designed to listen for client requests
and establish connections between the requestors. The Socket class is bidirectional
and can read and write data streams; however, data can be sent sequentially only
after a connection has been established with the destination address. The
InetAddress class represents an IP address at the I/O level and contains methods
that help to translate its form or check if the address is reachable within a certain
time period.

9.3. C++ Networking


Starting with C++17, the standard includes classes and functions for filesystem
management but remains devoid of networking interfaces. The Networking
Technical Specification proposes extensions for effective network programming.
The C++ REST SDK library provides asynchronous C++ interfaces for RESTful
services. Qt—designed primarily for GUI development—also contains a networking
programming module. Other C++ network programming frameworks include POCO,
ACE, and Boost ASIO (now an official Networking Technical Specification).

Asio's core network model is based on the Proactor design pattern, and it uses
either direct callback handlers or executors—which can be functions, functors, or
other callable objects—to inform the application of the completion of an
asynchronous operation. Most concurrent programming tasks share a general
pattern: using one or more threads to perform task actions and invoking callbacks
(directly or via other mechanisms) when a task or subtask completes. Consequently,
the Proactor pattern can be applied to a broad set of applications; it is useful not
only for asynchronous I/O operations but also whenever the application need not
block while waiting for a task or subtask to complete. The specific underlying
asynchronous operations that implement the Proactor pattern can be I/O or even
non-I/O operations. Furthermore, the handlers themselves need not be wrapped
around I/O operations: spawning a concurrent thread, performing computational or
mathematical calculations, or querying a database are all implementable within this
pattern.

10. Testing and Debugging Network Applications


Network applications that use the Berkeley Sockets Application Programming
Interface (API) often require a little more work than testing that it runs correctly.
Those that work with datagrams may require more testing to ensure that messages
are not being lost. There is a family of utilities that run on most well-known
operating systems (Windows, macOS and UNIX) called Ping, Traceroute (sometimes
called Tracert), PathPing, MTR and PingPlotter. They send Internet Control Message
Protocol (ICMP) control messages and are used to check for lost packets and round-
trip message time. They are similar to UDP because neither of the protocols
establishes a connection. The recent rise of cryptocurrencies has seen port scanning
increase ramatically as users look for weaknesses in the server's firewall using
applications such as Nmap. If a hole is found, then the server may be susceptible to
the "51% attack." This is because the attacker has access to the wallet.dat file that
contains all of the digital currency based on the Bitcoin blockchain.

A popular network server and client application pairing is Secure Shell (SSH). Both
the Server and Client can be run in a Debug mode to enable the logging of the packet
sequence and handshake process. The caveats are similar to that of enabling Debug
mode in any application: debugging information can show a lot of details and it may
or may not place a load on the system. Third-party software providers of special
server software will often have a Debug Mode or Debug Log feature built in with a
Stellar IP Address Lookup function. This Lookup function ties the service back to a
geographic location and server name to see things such as VPN usage, Origin,
Domain Name and other details.

10.1. Network Testing Tools


Verifying correct protocol operation is an essential part of network development.
Simulators can provide a convenient way to study protocols in complex setups that
can be difficult to reproduce in a lab. Testing a simulation model usually relies on
scrutinizing traces and outputs of the simulation, as well as on debugging the model.
Inspecting traces can be done automatically if the exchanged packets follow a pre-
defined format. However, especially in the early stages of development the
investigators often want to precisely control what traffic is injected into the system
and what is expected in response.

To limit the amount of test code and setup effort needed, one would like to describe
the tests as succinctly as possible, preferably in a notation similar to the protocols
involved. Packetdrill is a script-based tool developed by Google that runs on Linux-
based operating systems. The tool allows one to describe a test in which packets are
injected to the implementation undergoing tests, and from which the responses to
these injections are verified. It also allows one to call system calls at defined times to
bring the implementation into specific states. Packetdrill is thus useful both to inject
packet trains for many closed user group applications, and to trigger and observe
system calls for the network stack (Rüngeler & Tüxen, 2015).

10.2. Debugging Techniques


Debugging concurrent code is challenging enough, but network programming is
further complicated by asynchronous operations, the unreliable nature of networks,
and the interactions between many different devices. The debugging techniques
used to troubleshoot these situations are described here. (The primary debugging
facility in Go is the runtime/trace package.)

Trace data show every goroutine and when it was descheduled, the reason why it
was blocked, the corresponding stack traces, and an optional linearized log of user-
annotated events. Typical events include network-system-call completion, entering
or returning from a specific handler, completing a handshake, or whatever else the
developer deems interesting.

11. Real-world Applications of Network Programming


As our lives become increasingly digitized and integrated with social and economic
activities, it becomes easier to see how societal needs affect the requirements of
software applications. For example, intelligent public transportation systems must
provide accurate and timely information about estimated times of arrival, remaining
capacity, and impacts of road jams and accidents. This necessitates continuous
monitoring of buses and other public vehicles and linking them with users and other
concerned institutions.

Information about these vehicles can be captured through Global Positioning


Systems (GPS), and transmitted to the control center using Mobile Communication
Technology. The control center, equipped with Geographic Information System
(GIS) and various information services, processes and displays information on web
sites, enables user inquiries through Short Messaging Service (SMS), and transmits
required information to other institutions. This sophisticated application of several
Information and Communication Technology (ICT) areas imaginable])) required
potent knowledge in GUI design, DBMS, GIS, Network Programming, Mobile
Communication, and Android Programming.
11.1. Web Applications
Traditional network applications include e-mail, FTP, Telnet, and Internet Relay
Chat. However, the recent emergence of the World Wide Web (WWW) has changed
the face of networking. Web applications, in which the end user interacts with
others on the Internet using a standard Web browser, have become popular. Users
are thus spared the difficulty of learning the command syntax imposed by many
traditional network applications, and also of acquiring a special client program.

Web applications use client-server interaction with stateless communication. The


client sends a request to the server when it wants some information. The server
responds with the appropriate information and then literally forgets that the client-
requesting the information ever existed. Any future request from the client will
require the server to go through an authentication procedure once again.

11.2. Chat Applications


Users can easily communicate with each other without having to wait for long
periods of time (Thakur & Dhiman, 2021). It offers multidirectional exchange, so
even if the other end is not active, users can still send messages. The interface
enables the creation of chat rooms with live servers for sharing messages while on
the move. The application is straightforward, requiring no login, supporting
multiple users, and incorporating AJAX-style functionality. It comprises a client
application on the user device and a server program that hosts the chat room over
the network. Data flow diagrams provide an overview of the system, identifying
entities such as Chat, Chat History, Smiley Chat, Chat User, Chat Group, Chat Profile,
and Delete Conversation.

11.3. File Transfer Protocols


The File Transfer Protocol (FTP) is typically used to place files where they can be
accessed. UUGATE is a program designed to retrieve files using FTP and the ago mail
system and make them available on the user's local host. The File Transfer Protocol
(FTP) is designed to permit a user to copy files between two machines over a TCP
connection. These files can be copied to or from the remote machine and your local
machine. FTP defines two separate TCP connections—a control connection, which
remains open throughout a session and handles commands/responses, and a data
connection, established as necessary to transfer directory listings or files. The port
assignments are defined in RFC 1700.The FTP client makes the initial control
connection to the FTP server, operating on port 21, and sends a USER command,
followed by a password. When the client requires directory information or a file
transfer, it establishes a data connection.
For brief transaction sets, the data connection is closed after the listing or transfer
has completed. For longer series of transactions, the data connection may remain
open for some period of time. The port used by the client for the data connection
may be any port, while the server always uses port 20. FTP must be mode-aware,
which means that both sides must agree before the transfer on the pattern,
structure, and mode before a file is transferred. A brevity in this discussion has been
adopted, omitting the distinctions between FTP modes for much of the explanation.

12. Future Trends in Network Programming


The concept of the Future Internet is emerging from the synergy of billions of
mobile users, billions of sensors, connected in everything, and smart technologies
that create new digital worlds. This approach will support the actions of people, the
day-to-day business of companies, and shape the day-to-day world of each
Government, all within an interconnected world. These actions will be based on the
intelligent and pervasive use of billions of sensors and actuators in all
environments: connected things in everything. The goal is to sense and act on the
real world in smart ways or for real-time and intelligent control of the real world,
considering real-life constraints, such as safety, security, evacuation, etc. The focus
on things connected in everything needs to be complemented by the digitalization of
the whole world of creations and recognitions. Digital extensions will represent all
forms of traditional and new creative expression and archives, and will also cover
the creation and support of new forms of digital worlds and societies. In particular,
digital worlds will (1) allow the reproduction and presentation of creative
expression in ways not possible in the real world; (2) go beyond the reproduction of
what exists in the real world and create completely new and original worlds and
expressions; and (3) serve to both preserve and organize all forms of content from
the past and present for present and future access and understanding.

The major impact of the Digital Worlds aspect of the Future Internet will be on
creative expression and various forms of recognition. New models of digital content
created directly in digital form, or translated from their analog heritage, will come
together under common systems and infrastructure for distribution, delivery,
archiving, and management. These models will support both traditional
representations as well as new distributions. A second major impact will be on the
recognition and understanding of the digital world, with new infrastructure
required to support the recognition of speech, language, emotions, actions, video,
images, music, and other forms of digital content. It will also recognize the impact of
this content on search and understanding, and incorporate the broader aspects of
social communities and ambient context into the interpretation models.
12.1. Internet of Things (IoT)
The Internet of Things (IoT) envisions everyday objects equipped with
microcontrollers, transceivers, and protocols that enable communication with each
other and users, making the Internet more immersive and pervasive. IoT
applications include home automation, industrial automation, medical aids, energy
management, traffic management, and more, leveraging large amounts of data
generated by connected devices (Rajashekhar, 2016).

The core idea is the pervasive presence of objects such as RFID tags, sensors,
actuators, and mobile phones, which can interact and cooperate through unique
addressing schemes. IoT has the potential to significantly impact daily life and user
behavior in both domestic and industrial environments. Applications include
assisted living, e-health, enhanced learning, automation, logistics, and intelligent
transportation. Adoption challenges include technical difficulties and the lack of a
clear business model to attract investment for deployment.

IoT is an emerging global Internet-based technical architecture facilitating the


exchange of goods and services in supply chain networks, impacting security and
privacy. The term was first used by Kevin Ashton in 1999, and IoT was “born”
between 2008 and 2009. Currently, about 25 billion devices are connected to IoT,
with an expected increase to 50 billion by 2020. IoT enhances individuals’ quality of
life through new data access and services in education, security, healthcare, and
transportation. It boosts enterprise productivity by providing a distributed,
intelligent network of smart devices, enabling asset management, resource
optimization, and new business models. IoT offers benefits in tracking, data
management, and cost savings, and supports the creation of interconnected devices.
IPv6 (Internet Protocol Version 6) is necessary for IoT, providing an identification
and location system for network devices. IPv4, created in 1958 by DARPA, used 32-
bit numerical addresses, supporting about 3 billion devices worldwide (Salazar
Soler & Silvestre Bergés, 2017).

12.2. 5G Networking
The worldwide implementation of the 5G cellular network has been opening a new
era of communication, facilitating high data transfer speed and low latency
compared to previous mobile generations such as 4G. The 5G network has been
evolving, focusing on enhanced broadband mobile low latency and ultra-reliable
communications, and massive integration for machine communications. The still
deploying 5G network leaves many places out of coverage, leading to frequent
handovers to 4G and vice versa. 5G mmWave signals are more susceptible to
obstacles, reducing signal strength and causing packet losses and frequent handoffs.
These handoffs can cause significant delay and low throughput especially affecting
reliable data transfer protocols like TCP, which may experience spurious
retransmission timeouts during handovers. Using multiple communication
interfaces simultaneously can improve throughput and reduce delays, especially for
large file transfers. Many mobile operators deploy 4G and 5G infrastructure
together, often on the same towers in non-standalone setups, making both available
to user equipment. Concurrent use of 4G and 5G radios can enhance throughput
while full 5G implementation continues. Multipath TCP (MPTCP) enables devices to
use multiple communication interfaces simultaneously, providing a promising
solution for better performance during handovers (Mahmud et al., 2022).

13. Conclusion
This primer has covered the essential material for the introductory part of an upper-
level graduate networking course. It provides relatively concise descriptions of
network programming concepts that are crucial to the everyday work of network
and system designers and implementers.

Due to space considerations, many topics in network programming were omitted or


only briefly mentioned; others are detailed by the accompanying exercises and
projects. Accompanying lines of code are designed to illustrate important concepts
in a compact and straightforward format, often at some extra runtime cost. For
applications requiring greater efficiency, readers can implement the same programs
in a lower-level language such as C.

References:

Ionuţ Andreica, M., Olaru, V., Stanciu, V., & Ţăpuş, N. (2012). Design and
Development of a UDP-Based Connection-Oriented Multi-Stream One-to-Many
Communication Protocol, Journal of Telecommunications and Information
Technology, 2012, nr 1. [PDF]

Bukhowa, F. (2018). TCP Server and Client: Bookstore Enquiry. [PDF]

El-Alfy, E. S. M. (2007). ICS 343: Fundamentals of Computer Networks (3-3-4). [PDF]

Mohammed Khan, H., Chellin Chandran, D. J. G., & Kingsly, C. S. (2013). AN


INNOVATIVE ANGLE IN THE APPLICATION OF CRYPTOGRAPHY TO NETWORK
SECURITY. [PDF]

Klinefelter, J. (1997). How Secure Transactions are Achieved on the Internet using
SSL: An Honors Presentation of Internet Security Practices and Protocols. [PDF]
Rüngeler, I. & Tüxen, M. (2015). Integration of the Packetdrill Testing Tool in INET.
[PDF]

Thakur, A. & Dhiman, K. (2021). Chat Room Using HTML, PHP, CSS, JS, AJAX. [PDF]

Rajashekhar, M. (2016). A LITERATURE STUDY ON INTERNET OF THINGS FOR


SMART CITIES. [PDF]

Salazar Soler, J. & Silvestre Bergés, S. (2017). Internet of things. [PDF]

Mahmud, I., Lubna, T., & Cho, Y. Z. (2022). Performance Evaluation of MPTCP on
Simultaneous Use of 5G and 4G Networks. ncbi.nlm.nih.gov

You might also like