0% found this document useful (0 votes)
72 views

Operating System: Title

This document describes a project on a multi-threading client-server system for file accepting. The project was done by four group members for their Operating Systems course. It includes an abstract, introduction on key concepts like multithreading, clients, servers and sockets. It also discusses related works by other researchers in this area and proposes an algorithm for the client and server parts of the system. The contents section lists topics like the types of network communication, proposed method, results, server code, client code and conclusions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views

Operating System: Title

This document describes a project on a multi-threading client-server system for file accepting. The project was done by four group members for their Operating Systems course. It includes an abstract, introduction on key concepts like multithreading, clients, servers and sockets. It also discusses related works by other researchers in this area and proposes an algorithm for the client and server parts of the system. The contents section lists topics like the types of network communication, proposed method, results, server code, client code and conclusions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

School of Computer Science and Engineering

OPERATING SYSTEM
PROJECT COMPONENT

TITLE: MULTI-THREADING CLIENT SERVER


FOR FILE ACCEPTING

FACULTY :PROF.NAGARAJA RAO A


SLOT :F1+TF1
LAB :L53+L54
COURSE CODE : CSE2004

GROUP MEMBERS:
SAI PRATHAP REDDY :18BCE0111
C.GOWTHAM :18BCE0099
T.ADITYA REDDY :18BCE0045
E.PHANEENDRA :18BEC0061
CONTENTS:
1. ABSTRACT
2. INTRODUCTION
3. TYPES OF NETWORK COMMUNICATION
4. RELATED WORKS
i. Many of the researchers proposed many methods
5.PROPOSED METHOD/ ALGORITHM
6.RESULT AND DISCUSSION
7.SERVER CODE
8.CLIENT CODE
9.CONCLUSION
i. Current applications of client server mode.
ii. The future of client/server system.
10.REFERENCES

1.ABSTRACT:

This project is based on the concept of Distributed File-sharing Systems. A server


has specifically been designed to be the file store for a number of clients attached
to a local area network. In particular, these personal machines (clients) have a
very limited amount of memory with which to interface to the file server. The
filing system supports a hierarchical directory structure. Both the operations and
communication protocol supported by the file server are chosen to make a client
access to the files simple. Special attention is given for maintaining priority
among the clients. Various aspects of the implementation have been executed to
ensure the optimized functioning of the server
system.
2. INTRODUCTION:
i. Multithreading

A technique by which a single set of code can be used by several processors


at different stages of execution.

Fig 2.1

ii. Client
A client is a requesting program or user in a client-server relationship.

Fig 2.2

iii. Server
The computer handling the request and sending back the HTML file is a
server.
iv. Socket

Socket is an end point of communication between two systems on a network.


It is a combination of IP address and port on one system.
So, on each system a socket exists for a process interacting with the socket on
other system over the network.
A combination of local socket and the socket at the remote system is also
known a

„Four tuple‟ or „4-tuple


3.Types of network communication
• OSI

• TCP/IP
• While OSI is more of a theoretical model, the TCP/IP networking model
is the most popular and widely used.
• the communication over the network in TCP/IP model takes place in
form of a client server architecture
• client begins the communication and server follows up and a connection
is established.
• The Transmission Control Protocol (TCP) is one of the main protocols of
the Internet protocol suite.
• It originated in the initial network implementation in which it
complemented the Internet Protocol (IP). Therefore, the entire suite is
commonly referred to as TCP/IP
4.RELATED WORKS:

Many of the researchers proposed many methods:

Mehmet Aksit and Lodewijk Bergmans et al, in his paper “Composing


Multiple-Client- MultipleServer Synchronization” at TRESE project at
University of Twente presents that object- oriented concurrent languages must not
only support a single-server model, but cooperatively synchronizing servers as
well. This paper first classifies multi-server synchronization in five categories.
The intention here is to define a framework for evaluating current approaches and
identifying the requirements for designing new languages. In addition, this paper
presents a composable multi-server synchronization technique, adopting the
concept of composition-filters.

Yaoping Ruan, Vivek S Pai, Erich Nahum, John M Tracey at ACM


SIGMETRICS Performance evaluation review proposed paper “Evaluating
the impact of simultaneous multithreading on network servers using real
hardware” the performance of simultaneous multithreading (SMT) for network
servers using actual hardware, multiple network server applications, and several
workloads. Using three versions of the Intel Xeon processor with
HyperThreading, we perform macroscopic analysis as well as microarchitectural
measurements to understand the origins of the performance bottlenecks for SMT
processors in these environments and performance models yield much more
optimistic -benefits for SMT than we observe.

Josep Oriol Fit´o , Jordi Guitart proposed “Analyzing the Performance of a


Multithreaded
Application Server and its Limitations in a Multiprocessor Environment”
present an in-depth study of the performance of an application server in a
multiprocessor environment which process representative workloads of
nowadays.
.
Ms.Rupilaa V.M., Ms.Sangeetha M., Mr.Sathya Seelan K., Mr.Vadivel R. et al
in their
International Journal on Recent and Innovation Trends in Computing and
Communication proposed
“TCP Concurrent Echo Program using Fork and Thread” explained In
networking, client-server model plays a vital role in exchanging information
between processes. Client-server model predominantly relies on socket
programming. Sockets allow communication between processes on same or
different machines. Servers in the client-server model are of two types- Iterative
and Concurrent. This paper describes about the elementary socket function for
TCP client/server.

Joshua A. Redstone, Susan J. Eggers and Henry M. Levy et al Proceedings of the


9th International
Conference on Architectural Support for Programming Languages and Operating
Systems, November 2000 presents the first analysis of operating system execution
on a simultaneous multithreaded (SMT) processor. SMT is a latency-tolerant CPU
architecture that executes multiple instructions from multiple threads each cycle.
The ability to issue instructions from different threads provides better utilization
of execution resources by converting thread-level parallelism into instruction-
level parallelism.

Nima Kaveh and Wolfgang Emmerich et al proposed Deadlock Detection in


Distributed Object Systems The behaviour of a distributed system is largely
determined by the use of synchronization primitives and threading policies of the
underlying middleware.
Fig 4.1

5.PROPOSED METHOD/ALGORITHM

I. CLIENT:

/* ---------- INITIALIZING VARIABLES ----------- */

• client server are two file descriptors.


• These two variables store the values returned by the socket system call
and the accept system call.
• portNum is for storing port number on which the accepts connections.
• isExit is bool variable which will be used to end the loop.
• The server reads characters from the socket connection into a dynamic
variable (buffer).
• A sock addr_in is a structure containing an internet address. This
structure is already defined in netinet/in.h, so we don't need to declare
it again.

DEFINITION:
struct sockaddr_in
{ short sin_family; u_short sin_port;
struct in_addr sin_addr; char
sin_zero[8]
};
1. serv_addr will contain the address of the server.
2. socklen_t is an intr type of width of at least 32 bits.

/* ---------- ESTABLISHING SOCKET CONNECTION ---------- */


/* --------------- socket() function ----------------
- */ /* The socket() function creates a new
socket.
It takes 3 arguments,
• AF_INET: address domain of the socket.
• SOCK_STREAM: Type of socket. a stream socket in which characters are
read in a continuous stream (TCP)
• Third is a protocol argument: should always be 0. The OS will choose the
most appropiate protocol.
• This will return a small integer and is used for all references to this socket.
If the socket call fails, it returns -1.

/* ------------- LISTENING CALL ------------- */


/* --------- ------- listen()----------------- */
The listen system call allows the process to listen on the socket for
connections. The program will be stay idle here if there are no incoming
connections. The first argument is the socket file descriptor, and the second is
the size for the number of clients. the number of connections that the server
can handle while the process is handling a particular connection.
The maximum size permitted by most systems is 5.

/* ------------- ACCEPTING CLIENTS -------------- */ /*


----------------- listen() ------------------- */

The accept() system call causes the process to block until a client connects to the
server. Thus, it wakes up the process when a connection from a client has been
successfully established.
It returns a new file descriptor, and all communication on this connection should
be done using the new file descriptor.

The second argument is a reference pointer to the address of the client on the
other end of the connection, and the third argument is the size of this structure.
*/
/*

II. SERVER:

/* ---------- INITIALIZING VARIABLES ----------- */


• client is a file descriptor to store the values returned by the socket system
call and the accept system call.
• portNum is for storing port number on which the accepts connections.
• isExit is bool variable which will be used to end the loop
• The client reads characters from the socket connection into a dynamic
variable (buffer).
A sockaddr_in is a structure containing an internet address. This structure is
already defined in netinet/in.h, so we don't need to declare it again.

/* ---------- ESTABLISHING SOCKET CONNECTION ---------- */


/* --------------- socket () function ------------------ */
/*The socket () function creates a new socket. It takes 3 arguments,
a. AF_INET: address domain of the socket.

b. SOCK_STREAM: Type of socket. a stream socket


in which characters are read in a continuous stream
(TCP)

c. Third is a protocol argument: should always be 0.


The OS will choose the most appropiate protocol.

returns -1.
*/
/*
The variable serv_addr is a structure of
sockaddr_in. sin_family contains a
code for the address family.
It should always be set to AF_INET.
htons() converts the port number from
host byte order to a port number in
network byte order.
*/

/* ---------- CONNECTING THE SOCKET ----------- */


/* ---------------- connect() ----------------- */
/*
The connect function is called by
the client to establish a
connection to the server. It takes
three arguments, the socket file
descriptor, the address of the host
to which it wants to connect
(including the port number), and
the size of this address.
/*-------------FORKING THE
PROCESS ------------- */
/*----------------fork() --------------------- */

The fork() system call will be used to create multiple clients that will interact with
the server.
It returns a unique pid value for each clients or child process or request thus
helps in connecting to server individually.
/* ---------------- CLOSE CALL -------------- */
/* ----------------- close() ---------------- */*
Once the server presses # to end the
connection, the loop will break and it
will close the server socket connection
and the client connection
6.RESULT AND DISCUSSION
From the above project, a multithreaded client server system is successfully
established. With the use of operating system concepts like creating processes using fork()
and a little of networking concepts like socket programming is shown that when different
clients are requesting the server for interaction, the server create many child processes which
handles the request of different clients accessing the server. Thus, a system is created in which
clients and servers are connected to a common network.

Fig 6.1
7.SERVER CODE:
#include<stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#define PORT 4444

int main(){
int sockfd, ret;
struct sockaddr_in serverAddr;

int newSocket;
struct sockaddr_in newAddr;
socklen_t addr_size;
char buffer[1024];

pid_t childpid;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if(sockfd < 0){
printf("[-]Error in connection.\n");
exit(1);
}
printf("[+]Server Socket is created.\n");
memset(&serverAddr, '\0', sizeof(serverAddr));
serverAddr.sin_family = AF_INET;
serverAddr.sin_port = htons(PORT);
serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");

ret = bind(sockfd, (struct sockaddr*)&serverAddr,


sizeof(serverAddr));
if(ret < 0){
printf("[-]Error in binding.\n");
exit(1);
}
printf("[+]Bind to port %d\n", 4444);
if(listen(sockfd, 10) == 0){
printf("[+]Listening....\n");
}else{
printf("[-]Error in binding.\n");
}
while(1){
newSocket = accept(sockfd, (struct sockaddr*)&newAddr, &addr_size);
if(newSocket < 0){
exit(1);
}
printf("Connection accepted from %s:%d\n,
inet_ntoa(newAddr.sin_addr), ntohs(newAddr.sin_port));
if((childpid = fork()) == 0){
close(sockfd);
while(1){
recv(newSocket, buffer, 1024, 0);
if(strcmp(buffer, ":exit") == 0){
printf("Disconnected from
%s:%d\n",inet_ntoa(newAddr.sin_addr),
ntohs(newAddr.sin_port));
break;
}else{
printf("Client: %s\n", buffer);
send(newSocket, buffer, strlen(buffer), 0);
bzero(buffer, sizeof(buffer));
}
}
}

close(newSocket);

return 0;
}
SERVER OUTPUT:

Fig 7.1
8.CLIENT CODE:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#define PORT 4444


int main(){

int clientSocket, ret;


struct sockaddr_in serverAddr;
char buffer[1024];

clientSocket = socket(AF_INET, SOCK_STREAM, 0);


if(clientSocket < 0){
printf("[-]Error in connection.\n");
exit(1);
}
printf("[+]Client Socket is created.\n");

memset(&serverAddr, '\0', sizeof(serverAddr));


serverAddr.sin_family = AF_INET;
serverAddr.sin_port = htons(PORT);
serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");

ret = connect(clientSocket, (struct sockaddr*)&serverAddr,


sizeof(serverAddr));
if(ret < 0)
{
printf("[-]Error in connection.\n");
exit(1);
}
printf("[+]Connected to Server.\n");

while(1){
printf("Client: \t");
scanf("%s", &bufer[0]);

send(clientSocket,buffer, strlen(buffer), 0);

if(strcmp(buffer, ":exit") == 0){


close(clientSocket);
printf("[-]Disconnected from server.\n");
exit(1);
}

if(recv(clientSocket, buffer, 1024, 0) < 0){


printf("[-]Error in receiving data.\n");
}else{
printf("Server: \t%s\n", buffer);
}
}

return 0;
}

CLIENT 1:

Fig 8.1
CLIENT 2:

Fig 8.2

CLIENT 3 :

Fig 8.3
9. CONCLUSION
Client/server program for concurrent server using fork and thread is implemented
and show along with the execution. Synchronization problem exist with threads
which can be overcome by using mutex and condition variables. The advantage of
implementing this methods are the central management of server. Also this is
good for server administrator because they only have to be in one place and can
solve all the problems in one place as well. The configuration is simple to setup.
Moreover it takes less time to troubleshoot because troubleshooting takes place at
one physical server. The major problems that occurs due to this server client
model is that all the resources are located on one server , this creates a single
point of failure. It means that if anything should happen to the server such as a
crashed hard drive that is not recoverable, then all the resources that were once
hosted on that server will no longer be available.
(i) CURRENT APPLICATIONS OF CLIENT SERVER MODEL

Banking: Based on Internet personal banking. Consequently,the typical requests


of an online bank were simulated, such as login/logout, bank balance
inquiry,money transfers, look at and modify the user profile,etc. All of these
requests are based on SSL. Since in the first (and mandatory) transaction an SSL
connection is established, all the above mentioned requests are based on SSL.
Furthermore, the possible operations include both POST and GET HTTP
methods.

E-commerce, based on the workload characteristics of an e-commerce site. It was


designed to simulate a Web server that sells computer systems; this includes
allowing users to search,
browse,customize, and purchase products. In fact, a customer visiting the
emulated site passes through three distinct phases. The first is when the customer
browses the website, looking for a product. The second is the customization
phase, were the end user customizes the desired product. Finally, if the customer
wants to check out or buy the product, then he must use requests based on SSL

(ii) The Future of Client/Server Systems

The single-system image is a reality. In the future, cheap and powerful


workstation technology will be available to everyone—with truly distributed
applications using processing power wherever it is available and providing
information wherever it is needed. In the future, information will be available for
use by owners and authorized users, without the constant need for professional
systems developers and their complex programming languages. The future will
bring information captured at its source and available immediately to authorized
users.

The future will provide information from data in its original form: image, video,
audio, graphics, document, spreadsheet, or structured data, without the need to be
aware of specific software for each form. Successful organizations of the future—
those that are market-driven and competitive—will be ones using client/server as
an enabling technology to add recognized value to their product or service.
10.References:

[1] Computer Networking: Top-Down Approach – Jim Kurose


[2] Advanced Concepts in Operating Systems - Mukesh Singhal, Niranjan G.
Shivaratri [3] Online Sources – Wikipedia, GeekForGeeks, Stack Overflow, etc.
[4] Alizar B, Gabhane P, Gampawar A, Naraswani A,’File Transfer Protocol Client:
by using multithreding’,E-ISSN: 2249-3999,Volume2,issue 1,2012
[5] “Composing Multiple-Client-Multiple-Server Synchronization” by Mehmet
Aksit and Lodewijk Bergmans at TRESE project at University of Twente
[6] “Evaluating the impact of simultaneous multithreading on network servers
using real hardware” by
Yaoping Ruan, Vivek S Pai, Erich Nahum, John M Tracey at ACM SIGMETRICS
Performance
[7] Josep Oriol Fit´o , Jordi Guitart “Analyzing the Performance of a
Multithreaded Application Server and its Limitations in a Multiprocessor
Environment”
[8] Ms.Rupilaa V.M., Ms.Sangeetha M., Mr.Sathya Seelan K., Mr.Vadivel R. et al in
their International Journal on Recent and Innovation Trends in Computing and
Communication proposed “TCP Concurrent Echo Program using Fork and
Thread”
[9] Joshua A. Redstone, Susan J. Eggers and Henry M. Levy et al Proceedings of the
9th International
Conference on Architectural Support for Programming Languages and Operating
Systems, November 2000
[10] Nima Kaveh and Wolfgang Emmerich “Deadlock Detection in Distributed
Object Systems”

You might also like