Network Programming
Network Programming
Unit-1
Peer-To-Peer network
together with equal privilege and responsibilities for processing the data.
computers.
○ Client/Server network is a network model designed for the end users called
clients, to access the resources such as songs, video, etc. from a central
○ The central controller is known as a server while all other computers in the
3. Discuss about the Web server working method & Programming with example?
A web server is software and hardware that uses HTTP (Hypertext Transfer Protocol) and
other protocols to respond to client requests made over the World Wide Web. The main job of
a web server is to display website content through storing, processing and delivering webpages
to users. Besides HTTP, web servers also support SMTP (Simple Mail Transfer Protocol) and
FTP (File Transfer Protocol), used for email, file transfer and storage.
developers. But, actually, anyone who satisfies one of the below categories can use it-
● One who owns a website (to make the local copy on their system resemble what
is on the internet).
● One who wants to use server-side technologies, such as PHP or ColdFusion, can
A page on the internet can be viewed, when the browser requests it from the web server and the
web server responds with that page. A simple diagrammatic representation of this is given below in
the figure:
● Obtaining the IP Address from the domain name: Our web browser first obtains the
IP address the domain name resolves to. It can obtain the IP address in 2 ways-
● Browser requests the full URL: After knowing the IP Address, the browser now
● The web server responds to request: The web server responds to the browser by
sending the desired pages, and in case, the pages do not exist or some other error
● The browser displays the web page: The Browser finally gets the webpages and
Internet Protocol (IP) is the method or protocol by which data is sent from one computer
to another on the internet. Each computer -- known as a host -- on the internet has at
least one IP address that uniquely identifies it from all other computers on the internet.
IP is the defining set of protocols that enable the modern internet. It was initially
defined in May 1974 in a paper titled, "A Protocol for Packet Network
When data is received or sent -- such as an email or a webpage -- the message is divided into
chunks called packets. Each packet contains both the sender's internet address and the
receiver's address. Any packet is sent first to a gateway computer that understands a small
part of the internet. The gateway computer reads the destination address and forwards the
packet to an adjacent gateway that in turn reads the destination address and so forth until
one gateway recognizes the packet as belonging to a computer within its immediate
neighborhood -- or domain. That gateway then forwards the packet directly to the computer
What is an IP address?
IP provides mechanisms that enable different systems to connect to each other to transfer
Internet Protocols are of different types having different uses. These are mentioned
below:
10. IPv4
11. IPv6
Unit 2
Java Socket programming is used for communication between the applications running
on different JRE.
import java.io.*;
import java.net.*;
try{
String str=(String)dis.readUTF();
System.out.println("message= "+str);
ss.close();
}catch(Exception e){System.out.println(e);}
Socket Programming is a method to connect two nodes over a network to establish a means
of communication between those two nodes. A node represents a computer or a physical
device with an internet connection. A socket is the endpoint used for connecting to a node.
The signals required to implement the connection between two nodes are sent and received
using the sockets on each node respectively.
● 1. Socket creation:
● 2. Setsockopt:
● 3. Bind
● 4. Listen:
● 5. Accept:
Thread programming : Thread programming is about breaking down a program into smaller
threads that can run concurrently. Threads are like independent units of execution that
share the same memory space. They're used to improve program performance by allowing
Types of Threads
2. User-level thread.
User-level thread
The operating system does not recognize the user-level thread. User threads can be easily
blocking operation, the whole process is blocked. The kernel level thread does not know
The kernel thread recognizes the operating system. There is a thread control block and
process control block in the system for each thread and process in the kernel-level thread.
The kernel-level thread is implemented by the operating system. The kernel knows about
Unit 3
1. What is Java Beans?
○ It should be Serializable.
○ It should provide methods to set and get the values of the properties, known as
JavaBean Properties
A JavaBean property may be read, write, read-only, or write-only. JavaBean features are
accessed through two methods in the JavaBean's implementation class:
1. getPropertyName ()
For example, if the property name is firstName, the method name would be
getFirstName() to read that property. This method is called the accessor.
2. setPropertyName ()
For example, if the property name is firstName, the method name would be
setFirstName() to write that property. This method is called the mutator.
Advantages of JavaBean
Disadvantages of JavaBean
● Creating the setter and getter method for each property separately may lead to
Example –
Best examples of web services APIs are- SOAP (Simple object access protocol), REST.
Features :
● The application programming interface is also called a middle man between two
systems.
1. Open APIs –
It is also called public APIs which are available to any other users. Open APIs
2. Internal APIs –
It is also known as private APIs, only an internal system exposes this type of
APIs. These are designed for the internal use of the company rather than the
external users.
3. Composite APIs –
It is a type of APIs that combines different data and services. The main reason
execution process and improve the performance of the listeners in the web
interfaces.
4. Partner APIs –
● Weather snippets –
In weather snippets, APIs are generally used to access a large set of datasets
in day-to-day life.
● Login –
In this functionality, APIs are widely used to log in via Google, Linked In, Git
Hub, Twitter and allow users to access the log-in portal by using the API
interface.
● Entertainment –
In this field, APIs are used to access and provide a huge set of databases to
● E-commerce website –
In this, APIs provide the functionality like if you have purchase something, and
now you want to pay so, API provides interface like you can pay using different
bank debit cards, UPI(Unified Payments Interface), credit card, wallet, etc.
● Gaming –
In gaming, it provides an interface like you can access the information of the
game, and you can connect to different users and play with different-different
Unit 4
1. What are Packages in programming?
Ans.
A package in programming is a way of organizing and grouping related classes, interfaces,
functions, variables, and other elements that share a common purpose or functionality. A
package can also contain subpackages, which are packages inside another package. Packages
help to avoid naming conflicts, make the code easier to locate and use, and provide
controlled access to the members of the package. Different programming languages have
different ways of creating and using packages, but the general concept is similar.
● In Java, a package is a directory of Java files that have the same package name at
the top of the file. For example, java.util is a package that contains many utility
classes, such as ArrayList, Scanner, Random, etc. To use a class from a package, you
need to import it using the import statement, such as import java.util.ArrayList;1
● In Python, a package is a directory of Python files that have an __init__.py file
inside it. For example, numpy is a package that contains many modules for scientific
computing, such as numpy.array, numpy.linalg, numpy.random, etc. To use a module
from a package, you need to import it using the import statement, such as import
numpy.array;2
● In C#, a package is a collection of assemblies that are distributed and installed
together. For example, System is a package that contains many assemblies for
common tasks, such as System.IO, System.Net, System.Text, etc. To use a class
from an assembly, you need to add a reference to it using the using statement, such
as using System.IO;
It is a protocol designed for micro-browsers and it enables access to the internet in mobile devices.
WAP Model
The user opens the mini-browser in a mobile device. He selects a website that he wants to view. The
mobile device sends the URL encoded request via network to a WAP gateway using WAP protocol.
The WAP gateway translates this WAP request into a conventional HTTP URL request and sends it over
the internet. The request reaches to a specified web server and it processes the request just as it would
have processed any other request and sends the response back to the mobile device through WAP
gateway in WML file which can be seen in the micro-browser.
contains mobile device specifications and content development programming languages like
WML.
2. Session Layer: This layer contains Wireless Session Protocol (WSP). It provides fast
3. Transaction Layer: This layer contains Wireless Transaction Protocol (WTP). It runs on top
of UDP (User Datagram Protocol) and is a part of TCP/IP and offers transaction support.
4. Security Layer: This layer contains Wireless Transport Layer Security (WTLS). It offers data
5. Transport Layer: This layer contains Wireless Datagram Protocol. It presents consistent
The java.net package of the Java programming language includes various classes and
interfaces that provide an easy-to-use means to access network resources. Other than
classes and interfaces, the java.net package also provides support for the two well-known
network protocols. These are:
Firewall:
A firewall is a network security system that monitors and controls incoming and outgoing
network traffic based on a defined set of security rules. Its primary purpose is to
establish a barrier between a secure internal network and untrusted external networks,
such as the internet. Firewalls can be implemented in both hardware and software forms.
Firewalls have been a first line of defense in network security for over 25 years.
● Packet Filtering: Examines packets of data and makes decisions to allow or block
based on predefined rules.
● Stateful Inspection: Keeps track of the state of active connections and makes
decisions based on the context of the traffic.
● Virtual Private Network (VPN) Support: Enables secure communication over the
internet by encrypting data traffic.
Digital Signature:
A digital signature is a cryptographic technique used to verify the authenticity and
integrity of digital messages or documents. It provides a way to ensure that the message
or document has not been altered and that it was indeed created by the claimed sender.
● Private Key: The signer uses their private key to create the digital signature.
● Public Key: The recipient uses the public key (which is available to everyone) to
verify the digital signature.
● Hash Function: A cryptographic hash function generates a fixed-size string of
characters (the hash) from the content of the message. The hash is then signed
with the private key.
Process of Digital Signature:
1. The sender uses a hash function to generate a unique hash value for the message.
2. The sender encrypts the hash value with their private key, creating the digital
signature.
3. The digital signature is sent along with the message to the recipient.
4. The recipient uses the sender's public key to decrypt the digital signature,
obtaining the hash value.
5. The recipient independently computes the hash value of the received message.
6. If the computed hash matches the decrypted hash from the digital signature, the
message is verified as authentic and unaltered.
Security Techniques:
Various security techniques complement firewalls and digital signatures to enhance overall
cybersecurity. Some key techniques include:
● Encryption: Protects data by converting it into a secure format that can only be
decrypted by authorized parties.
● Multi-Factor Authentication (MFA): Requires users to provide multiple forms of
identification before granting access, adding an extra layer of security.
● Intrusion Detection and Prevention Systems (IDPS): Monitor network or system
activities for signs of malicious behavior and take preventive actions.
● Security Auditing and Monitoring: Regularly review and analyze system logs to
identify and respond to security incidents.
● Access Controls: Restrict and manage user access to systems and data based on
their roles and responsibilities.
● Vulnerability Assessment and Patch Management: Regularly scan systems for
vulnerabilities and apply patches to address known security issues.
● Security Awareness Training: Educate users about security best practices to
reduce the risk of social engineering attacks.
Unit 5
1. Write about the client side programming?
Ans.
Client-side programming refers to the execution of code on the user's device (typically a
web browser) rather than on the server. This type of programming is integral to creating
dynamic and interactive user interfaces on the web.
Client-side programming plays a pivotal role in creating dynamic, responsive, and
interactive web applications. As technology continues to evolve, staying updated on the
latest client-side development trends and best practices is essential for building modern
and efficient user interfaces.
Here are key aspects and technologies associated with client-side programming:
1. Languages:
HTML (Hypertext Markup Language): Defines the structure and content of web pages.
CSS (Cascading Style Sheets): Controls the presentation and styling of HTML elements.
JavaScript: The primary client-side scripting language. JavaScript allows for dynamic
content, interactivity, and manipulation of the Document Object Model (DOM) in the
browser.
React, Angular, and Vue.js: Modern JavaScript frameworks for building single-page
applications (SPAs) with dynamic user interfaces.
Using python:
import requests
url = 'https://example.com/path/to/file.txt'
# Make a GET request to the server
response = requests.get(url)
# Check if the request was successful (status code 200)
if response.status_code == 200:
# Access the content of the file
file_content = response.content
# Save the content to a local file
with open('local_file.txt', 'wb') as local_file:
local_file.write(file_content)
else:
print(f"Failed to retrieve file. Status code: {response.status_code}")
Step-by-Step Explanation:
● Specify the URL: Define the URL of the file you want to retrieve.
● Make an HTTP GET Request: Use a library or tool that can send HTTP requests. In the
example above, the requests library in Python is used. The get method is employed to
make a GET request to the specified URL.
● Check the Response Status Code: The server responds with a status code indicating
the success or failure of the request. A status code of 200 typically indicates success. If
the status code is different, it may indicate an error, and you can handle it accordingly.
● Access the File Content: If the request is successful, you can access the content of the
file from the response object. In the example, response.content contains the binary
content of the file.
● Save the File Locally: Save the content to a local file. In the example, the content is
written to a file named 'local_file.txt' in binary mode ('wb'). Adjust the file name and mode
based on your needs.
When a user interacts with a web application, the browser initiates a connection to the
server hosting the application. This connection is typically established using the HTTP
(Hypertext Transfer Protocol) protocol, which defines the rules for exchanging
messages between clients and servers.
The browser initiates the connection by sending an HTTP request message to the
server. This request message contains various information, including:
Upon receiving an HTTP request message from the browser, the server initiates the
process of accepting the connection. This involves several steps:
This process of accepting connections from browsers and responding to their requests
is the foundation of web application development, enabling dynamic and interactive
experiences for users.
4. Explain the Server Class? Also discuss about Server side programming.
The term "Server Class" typically refers to a class in programming that is designed
to handle server-related functionalities. It could be specific to a programming
language, framework, or library. This class would usually be responsible for
managing incoming requests, handling connections, and performing server-side
tasks in the context of applications or systems that involve server-side
programming.
Server-side programming involves writing code that runs on the server to manage
the core logic, process data, interact with databases, and handle requests from
clients, ensuring secure and scalable functionality for web applications.
It is the program that runs on server dealing with the generation of content
of web page.
Examples :
The Programming languages for server-side programming are :
1) PHP
2) C++
3) Java and JSP
4) Python
5) Ruby on Rails
Frameworks and Libraries: Developers often use frameworks and libraries to
streamline server-side development.
For example:
● Express.js (Node.js): A lightweight web application framework.
● Django (Python): A high-level Python web framework.
● Spring Boot (Java): Simplifies the development of Java-based
applications.
● Ruby on Rails (Ruby): A full-stack web application framework.