ALTERNATE SERVER AND MESSAGE PASSING

A PROJECT REPORT Submitted by

P.BALAMURUGAN (30605104012) G.KARTHICK (30605104023)
in partial fulfillment for the award of the degree

of

BACHELOR OF ENGINEERING
in COMPUTER SCIENCE AND ENGINEERING JEPPIAAR ENGINEERING COLLEGE, CHENNAI – 600 119

ANNA UNIVERSITY: CHENNAI 600 025
MAY 2009 i

JEPPIAAR ENGINEERING COLLEG DEPARTMENT OF COMPUTER SCIENCE AMD ENGINEERING JEPPIAAR NAGAR, OLD MAMALLAPURAM ROAD, CHENNAI-600 119

BONAFIDE CERTIFICATE Certified that this project report “ ALTERNATE SERVER AND
MESSAGE PASSING ” is the bonafide work of “ P.BALAMURUGAN (30605104012) and G.KARTHICK (30605104023)” who carried out the project work under my supervision.

Submitted for the examination held on……………………

PROJECT GIUDE

HEAD OF THE DEPARTMENT

INTERNAL EXAMINER

EXTERNAL EXAMINER

ii

DEDICATED TO OUR BELOVED PARENTS AND FRIENDS

ACKNOWLEDGEMENT .

M. for providing me an excellent infrastructure and valuable resources for carrying out this project. Project Coordinator and Internal Guide for their guidance towards the successful completion of he project.L..ACKNOWLEDGEMENT I am very much indebted to our chairman. (Engg). Ph...Sc.D. and the Secretary Thiru. (Ph. Phil.A. Sushil Lal Das M.. Regeena Wilson B.. Chinnadurai M. the Directors Thiru N. Tech. Ed. P.A. .B.B.. Jeppiaar M..A.. B. M. Thiru Dr..D.. Tech.. I wish to thank our Head of the Department. Last but not the least. B. Marie Wilson B.D) Principal Dr.D) and Mrs. I wish to acknowledge my parents for their kind support and being with me at my times of sorrow and also for bringing me coffee whenever I wanted. Ph. (Ph..

ABSTRACT .

The alternate server is the second client of the main server. The information that is maintained by the main server is updated to the alternate server. trademarks such as the proxy-server and the alternate sever is responsible for its reliability thus making UNIX has so far the dominant operating system of the emerging era. . The main server gets detached and the signals are also stopped. To avoid such a crisis we go for a Backup-Server which maintains the connection status of the Client and is updated then to then such that the connection may be resume with the Alternate Server acting as the Main-Server. In case the Server crashes then there lies a breakdown in the entire system left with the client unable to communicate. While the best possible security is availed through the File Management System. The clients are connected automatically to the alternate server by sending the signals. The updation is carried out by the constant time intervals. Our focus on the implementation of an Alternate Sever. This can be indicated by sending signals.ABSTRACT The UNIX operating system trades upon the labels of security and reliability. The alternate server assumes that the main server crashes and the alternate server take part of the communication process. The Client is the process that requests service from a remote process known as the Server which sends back the reply to the client.

TABLE OF CONTENTS

TABLE OF CONTENTS
CHAPTER NO TITLE PAGE NO

ABSTRACT LIST OF FIGURE LIST OF TABLES 1. INTRODUCTION 1.1 Server Crashing 1.2 Alternate Server 2. 3. LITERATURE REVIEW SYSTEM ANALYSIS 3.1 Existing System 3.2 Proposed System 3.3 Problem Description 4. SOFTWARE HARDWARE ENVIRONMENT 4.1 Operating System 4.1.1 LINUX operating system 4.1.2 Red Hat Linux 5.1 4.1.3 History of LINUX 4.2 About the language 4.2.1 UNIX operating system 4.2.2 UNIX environment 4.3 Hardware Description 4.4 Software Description

iii vi vii 1 1 2 4 5 5 5 6 7 7 7 7 8 9 9 10 10 11

5.

SYSTEM DESIGN 5.1 Block Diagram 5.2 Data Flow Diagram 5.3 Socket programming 5.3.1 Socket Creation and Naming 5.3.2 Connecting Stream Sockets 5.3.3 Datagram Sockets 5.3.4 Socket Options 5.4 Signals 5.4.1 Handling Signals

12 12 15 17 19 21 22 25 26 27 28 28 29 30 30 31 32 33 34 36 40 46 49 50 51 51 61

6.

PROJECT DESCRIPTION 6.1 Main server 6.2 Alternate Server 6.3 Client 6.4 Structured used 6.4.1 Pre Defined Structure 6.4.2 User Defied structure 6.5 File handling 6.5.1 Function Used 6.6 Signals 6.7 Client Server Model

7. 8. 9. 10.

TESTING AND IMPLEMENTATION CONCLUSION REFERENCE APPENDIX 10.1 Coding 10.2 Screen Shots

LIST OF FIGURES .

2 5.3.1(b) STATE TRANSTITION OF CLIENT STREAM SOCKET 22 23 5.3.1.2 5.1 AITERNATE SERVER AND MESSAGE PASSING 12 13 14 15 16 5.3.2.3.LIST OF FIGURE FIG NO TITLE OF FIGURE PAGE NO 5.2.1(a) BEFORE SERVER CRASHING AT THE TIME OF SERVER CRASHING DATAFLOW DIAGRAM FAILURE OF THE MAIN SERVER STATE TRANSTITION OF SERVER STREAM SOCKET 20 5.1.3(b) STATE TRANSTITION OF DATAGRAM SOCKET ALTERNATE STATE TRANSTITION OF DATAGRAM SOCKET 24 25 5.1.3(a) 5.3.3 5.1 5.4 OSI LAYER vi .

LIST OF TABLES .

1 TITLE OF TABLE MACRO SIGNALS HEADER FILES PAGE NO 37 vii .LIST OF TABLES TABLE NO 1.

Chapter 1 INTRODUCTION .

problems can occur. Crashing also causes several other problems. the file transfer process will be affected entirely. One widely implemented solution is to permit clients to lock files before using them. Moreover. INTRODUCTION 1. a large amount of data that has been previously transferred prior to the crash will be transferred once again causing redundancy.1 SERVER CRASHING Network file servers have multiple clients to take care of. One of them is when the server crashes.1. When the client is in the process of receiving an important file from a remote file server and if the file server happens to crash. In this case. When a client sends the message and the destination client‟s name to the server and after receiving the message. no locks are remembered. if the server happens to crash then the message will never be transferred to the receiver and the sender will never come to know of this. But locking introduces several annoying problems. After the server restarts.  The file server can retain the information about the last set of bytes that has been transferred and continue from the next set of bytes. this process may turn out to be more complicated when the number of clients is more.  Crashing of server can also be more problematic if the server is used for transferring messages between the clients in a small network. . If two or more clients should accidentally happen to decide to access the same file at more or less the same time.  The file transfer can be started once again from the beginning. This solution can have many synchronization problems.

the status of its operations with each of its clients at regular intervals. The Alternate Server receives the status of the main server and updates the information in a separate file. Initially when a client wants to log on to the main server.e. we have proposed the idea of implementing an Alternate Server which overcomes all these inherent problems. The server performs its bookkeeping operations by constantly sending the Alternate Server of its status i. The interval can be set to any desired value. So . it connects to the appropriate port number of the main server. This is how the main server distinguishes the Alternate Server from the rest of its clients.2 ALTERNATIVE SERVER In this proposed system the alternate server takes the role of a backup to the main server. In addition to being the first client of the main server.So to counter these problems associated with the server crashing. This host termed as the Alternate Server is dedicated solely to this particular main server. As the operations carried out by the main server (File Transfer & Message Transfer) are of utmost importance and its crashing may cause serious problems the server engages a separate host to act as its backup. 1. The clients are not aware of the fact that an alternate server exists. the alternate server should also act as the server for the clients as soon as the main server crashes. The alternate server will be the „first‟ client to connect to the main server.

ALTERNATE-SERVER contained a domain name rather than an IP address and port. .the alternate server is bound to another port number and IP address where it listens for the clients to connect to it. After the server crash. The alternate server then resumes the operations for each of the clients at the stage where they were interrupted when the main server crashed. the clients will connect to the port number and IP address to which the alternate server is bound. Once the main server crashes. The alternate server may continue to process the clients requests till the main server restarts after which the clients may connect to the main server once again. the alternate server will be able to accept any new client which connects for request.

Chapter 2 LITERATURE REVIEW .

By implementing this project. LITERATURE REVIEW The main objective of the proposed system is to overcome the problem of server crashing. though certainly not perfect. This project mainly deals with the transfer of files during the server crashing. the redundancy is reduced which is the major advantage. there is no other way to resolve it. The files are transferred by made the request by the clients. the language find only clumsy solutions to a problem are write programs to do jobs that existing tools handle easily. In a broader sense. . the elegant solutions are not easy to see without some experience and understanding. Of course. The UNIX system has become very popular. and command languages. programs for copying and printing files and so on. When the server gets crashed.2. but also essential programs like compilers. Time and again. the fraction of its users who are skilled in its application has decreased. This is very useful. The server maintains the status of the client and the files. because the server is the main part for the transfer of files. Thus the UNIX system is well suited for this project. editors. The UNIX system. More number of file is transferred at the same time. It also concentrates on the message passing. and there are a number of versions in wide use. This is done through Linux using the Unix C coding. The Linux is very effective for this project. UNIX is often taken to include not only the kernel. As the UNIX system has spread. is a marvelous computing environment.

Chapter 3 SYSTEM ANALYSIS .

3. So many files are transferred at the same time. which is more versatile and secure than windows environment. the server is the main part for the reliable transfer. In the network file transfer processing. there is a lack of fault tolerance. It is slightly difficult to achieve the reliability in the file transferring process 3. The servers maintain the status of the clients and the information about the files.2 PROPOSED SYSTEM As system like this has‟ been implemented in any other platform so for. The files are transferred from one client to another through the servers. During the process when the server gets crashed.1 EXISTING SYSTEM In the existing system. the server is switched off and it is rebooted from its initial stage. The whole project is based on UNIX OS. SYSTEM ANALYSIS 3. In the event of failure of any kind with the main server the whole .

3. the file that is transferred at the time of crashing is again transferred from the starting bytes. By the introduction of the proposed system. The alternate server is activated from the time of the crashing of main server. All the clients that are connected to the main server are automatically connected to the alternate server by modify its port address. the redundancy will be occurred. the alternate server is the backup of the main server. When the main server is crashed. In this case.network will be restored in no-time with the implementation of this system In this method. Due to this.3 PROBLEM DESCRIPTION The problem in the existing is that when the main server is crashed it is rebooted again. the redundant will be reduced to a large extent. . The files that are requested by the clients are transferred accurately to its destination file address. the signals are passed from the main server to the alternate server are stopped and the alternate server is activated.

Chapter 4 SOFTWARE AND HARDWARE ENVIRONMENT .

The goal has been to create a UNIX clone. free of any commercially copyrighted software. This license preserves software copyrights. but ensures distribution of programs with source code.4. . scanners. which acts as a communication service between the hardware (or physical equipment of computer) and the software (or applications which uses the hardware) of a computer system. which the entire world can use. tape drives. upgrade and share.1. and is easy to download. printers.1. 4. SOFTWARE AND HARDWARE REQUIREMENTS 4. Linux is distributed over the Internet. New features of the latest versions of the Linux kernel and the distribution include the following: Increase support for a wide variety of devices such as sound cards. Linux is distributed under the terms of the Free Software Foundation‟s GNU General Public License or GPL.1 LINUX Operating Systems LINUX is an Operating System for several types of computer platforms.1 Linux is an OS. hard disks.2 Red Hat Linux 5.1 OPERATING SYSTEM 4. The system has been designed and built by hundreds of programming scattered around the world. digital cameras and joy sticks. but primarily for Intel-based PCs.

Since then. FSF's goal is stable.1. Torvalds posted an early version of Linux on the Internet in 1991. Thus. The initial version was written by Linus Torvalds. high quality. the Linux distributions that you see today are the product of FSF's GNU project. Torvald‟s individual effort. such as those offered by Sun Microsystems. Linux is a full-featured UNIX system that runs on all of these platforms and more. a number of people. configuration and system maintenance with dozens of different GUI program. Linux has now made significant penetration into the corporate world [MANC00]. Today. Key to the success of Linux has been its character as a free package available under the auspices of the Free Software Foundation (FSF). which he then released under the GPL. Torvalds used GNU tools in developing his kernel. have contributed to the development of Linux. 4. and Silicon Graphics.3 History of LINUX Linux started out as a UNIX variant for the IBM PC architecture. many of which surpass commercial software peers in convenience and ease of use. a Finnish student of computer science. and many collaborators all over the world. platform-independent software that is free. collaborating over the Internet. Because Linux is free and the source code is available. all under the control of Torvalds. FSF's GNU project provides tools for software developers. and the GNU Public License (GPL) is the FSF seal of approval. Digital Equipment Corp Compaq). . In addition to its use by many individual programmers. This is not primarily because of the free software.Increasingly easier installation. it became an early alternative to other UNIX workstations. and embraced by the user community. but because of the quality of the Linux kernel.

resulting in a technically impressive product.2. 4. vendors can tweak applications and utilities to meet specific requirements. no single program or idea makes it work well . Moreover.1 UNIX Operating System UNIX is an operating system that allows a user and a computer to interact. This is the strong commercial advantage. 4.Many talented programmers have contributed to the current version. the University of California Berkeley) made many enhancements to the program and . a philosophy of using the computer. we (yes. it is a good operating system especially for programmers. with the source code available. The special features of UNIX are.2 ABOUT THE LANGUAGE Unix is a time sharing operating system kernel a program that control the sources of a compiler and allocates them among its users . Plus.The Unix operating system is rich and productive .The thing which makes it effective is an approach to programming. This makes it easy to squeeze optimal performance from a variety of hardware platforms.  The source code is available and written in a high-level language. Linux is highly modular and easily configured.  Because it is written in C.Even though. it is portable – UNIX systems run on a range of computers from microprocessors to the largest mainframes. Initially developed at Bell Laboratories in the early 1970‟s. the Unix system introduces a number of innovative programs and mechanisms.  Most important. which makes system easy to adapt to particular requirements.

The prompt in UNIX is usually your email address or the machine name. You must always finish a command by hitting return (or enter). An important note on UNIX: it is case sensitive!! This means that when logging in. If you‟re familiar with Windows or DOS.2. folders. with different drawers. . like all the characters you typed for your paper for Underwater Basket Weaving 112C. you‟ll be happy to know that UNIX works almost exactly the same as Windows and DOS when it comes to files and directories. your password may be “g0be8rs” but if you type in “G0BE8RS” UNIX will not recognize it as correct. there are many different versions of UNIX. A file is a bunch of information stored together. multi-tasking.2 UNIX environment UNIX saves everything in files and directories. and also files within the folders. Interactive operating system. multi-user.our version of UNIX began to diverge from the Bell Labs version. The UNIX system uses a prompt to tell you it is ready to accept your next command. This is similar to a prompt you would see if you were using DOS on a PC/IBM machine. The computer organizes the files like a file cabinet. A directory is a container for files (equivalent to a folder for Windows 95 or Mac gurus). Today. Just imagine if you worked in an office where everyone threw their work in one big pile in the corner!! With file cabinets (and the file/directory structure in UNIX) we don‟t have that problem! 4. followed by the number of times you‟ve seen the prompt during your current session. UNIX is a general. 4.3 HARDWARE DESCRIPTION To develop this system the IBM compatible personnel computer with a Pentium III process was used.

UNIX Programming Language : .Main processor Cache Hard disk Floppy drive CD drive Monitor RAM Keyboard Mouse : Intel Dual core 3.Its helps the developer or the analyst to understand the system .44 MB : 52X CD-ROM : 17‟‟ LCD Color Monitor : 1 GB : Samsung : Logitech 4. documentation and product catalogues etc. The software specification are the only basic for the manuals. Operating System : Linux.3 MHZ : 250 KB : 120 GB : 1. function to be established.4 SOFTWARE DESCRIPTION The main purpose of software description is the clear definition and specification functionality and of the interface of the software product.

Chapter 5 SYSTEM DESIGN .

1 BLOCK DIAGRAM Fig 5. SYSTEM DESIGN 5.5.1.1 ALTERNATE SERVER AND MESSAGE PASSING .

Fig 5.1.2 BEFORE SERVER CRASHING .

Fig 5.3 AT THE TIME OF SERVER CRASHING .1.

2.5.1 REGISTRATION AND TRANSACTION .2 DATA FLOW DIAGRAM  Registration & Transaction Registration Request Message CLIENT DATABASE CONNECTIN G CLIENT Reply Data Request TRANSACTIO N IN SERVER SERVER DB Fig 5.

2.2 FAILURE OF THE MAIN SERVER . FAILURE SIGNAL MESSAGES BY ALTERNATE SERVER AT PERIODIC INTERVALS BY TIME Signal VALIDITY BY SIGNAL Signal Transaction update message CONTINUE WITH EXISTING SYSTEM No CONNECT CLIENT WITH ALTERNATE SERVER Yes Server Failure LOG FILE Fig 5.

A Socket types define the communication properties visible to the application. A stream socket -. Sockets connect only with sockets in the same domain. A socket domain is an abstraction that provides an addressing structure and a set of protocols. reliable. like other forms of IPC. A socket is an endpoint of communication to which a name can be bound.x Sockets can be used to communicate between processes on a single system. sequenced. The socket address space between connected systems is called the Internet domain. Twenty three socket domains are identified (see <sys/socket. and unduplicated flow of data with no record boundaries. Processes communicate only between sockets of the same type.h>). There are five types of socket. Internet domain communication uses the TCP/IP internet protocol suite. Sockets exist in communication domains. of which only the UNIX and Internet domains are normally used Solaris 2. The UNIX domain provides a socket address space on a single system. . Sockets are very versatile and are a basic component of interprocess and intersystem communication.provides two-way.5. Sockets can also be used to communicate between processes on different systems. UNIX domain sockets are named with UNIX paths. It has a type and one or more associated processes.3 SOCKET PROGRAMMING Sockets provide point-to-point. A stream operates much like a telephone conversation. two-way communication between two processes.

which.The socket type is SOCK_STREAM. sequenced. The socket type is SOCK_DGRAM. A sequential packet socket Its provides a two-way. connection. A datagram socket It supports a two-way flow of messages. . reliable. No protocol for this type has been implemented for any protocol family. Record boundaries in the data are preserved. A on a datagram socket may receive messages in a different order from the sequence in which the messages were sent. uses Transmission Control Protocol (TCP). A raw socket A raw sockets are provides access to the underlying communication protocols. in the Internet domain. The socket type is SOCK_SEQPACKET. uses User Datagram Protocol (UDP). which. but their exact characteristics depend on the interface provided by the protocol. for datagram‟s of a fixed maximum length. in the Internet domain. Datagram sockets operate much like passing letters back and forth in the mail. These sockets are usually datagram oriented.

A remote process has no way to identify a socket until an address is bound to it. (struct sockaddr_un *) &addr.h> .. depending on the domain of the socket. length). In most domains. use #include <netinet/in. In the UNIX domain..  bind (sd. If the path of a UNIX domain socket requires more characters. If a protocol is not specified. There are three different ways to call bind(). you can:  #include <sys/socket.3. int bind(int s.. . a connection is usually composed of one or two path names. int namelen) is called to bind a path or internet address to a socket.. For Internet domain sockets.. int protocol) is called to create a socket in the specified domain and of the specified type.1 Socket Creation and Naming int socket(int domain. In the Internet domain. the system defaults to a protocol that supports the specified socket type. or fewer characters.h> ..    bind (sd. (struct sockaddr *) &addr.5. a connection is composed of local and remote addresses and local and remote ports.h> .    bind (sd. Communicating processes connect through addresses. connections must be unique. length). int type. (struct sockaddr_in *) &addr. length). use: #include <sys/un.For UNIX domain sockets with paths containing 14. const struct sockaddr *name. The socket handle (a descriptor) is returned.

Fig 5.1 (a) STATE TRANSITION OF SERVER STREAM SOCKET . Use unlink() or rm () to remove the socket. binding a name creates a named socket in the file system.In the UNIX domain.3.

5. length). For a SOCK_STREAM socket. connect (sd. the server calls accept(3N) to complete the connection.2 Connecting Stream Sockets Connecting sockets is usually not symmetric.. It then blocks on the socket. (struct sockaddr_in *)&server. ...3. A UNIX domain call is like this: struct sockaddr_un server. . the server calls int listen(int s. connect (sd. struct sockaddr *name.. One process usually acts as a server and the other process is the client. A client initiates a connection to the server's socket by a call to int connect(int s. which specifies how many connection requests can be queued. (struct sockaddr_un *)&server. The server binds its socket to a previously agreed path or address. while an Internet domain call would be: struct sockaddr_in. If the client's socket is unbound at the time of the connect call. For a SOCK_STREAM socket. int *addrlen) returns a new socket descriptor which is valid only for the particular connection. length). A server can have multiple SOCK_STREAM connections active at one time. the system automatically selects and binds a name to the socket. int accept(int s. int backlog) . . struct sockaddr *addr. int namelen) .

Fig 5.3.1(b) STATE TRANSITIONS OF A CLIENT STREAM SOCKET

5.3.3 Datagram Sockets A datagram socket does not require that a connection be established. Each message carries the destination address. If a particular local address is needed, a call to bind() must precede any data transfer. Data is sent through calls to sendto() or sendmsg(). The sendto() call is like a send() call with the

destination address also specified. To receive datagram socket messages, call recvfrom() or recvmsg(). While recv() requires one buffer for the arriving data, recvfrom() requires two buffers, one for the incoming message and another to receive the source address.

Fig 5.3.3 (a) STATE TRANSITION OF A DATAGRAM SOCKET Datagram sockets can also use connect () to connect the socket to a specified destination socket. When this is done, send () and recv () are used to send and receive data.

Fig 5.3.3 (b) ALTERNATE STATE TRANSITION OF A DATAGRAM SOCKET

accept () and listen () are not used with datagram sockets.

4 Socket Options A Sockets have a number of options that can be fetched with getsockopt() and set with setsockopt(). Application Layer (RPM Server) Application Layer (RPM Server) Transport Layer (UDP) Transport Layer (UDP) Network Layer (IP) Network Layer (IP) Link Layer & Physical Layer Link Layer & Physical Layer Transmission Line Fig 5.5. To manipulate options at any other level the protocol number of the desired protocol controlling the option of interest must be specified (see getprotoent() in getprotobyname()).3.4 OSI LAYERS .3. These functions can be used at the native socket level (level = SOL_SOCKET). in which case the socket option name must be specified.

.  Reliable Connection Oriented Byte Stream  Reliable Connection Oriented Packet Stream  Unreliable Packet Stream After creating a socket with one of the above special types it is bound to a 32 bit integer.  Signals having to do with unrecoverable error conditions during a system call. Sockets can be created and destroyed dynamically. The signals may be classified as follows:  Signals having to do with the termination of a process. This is achieved by means of socket. A socket is made to associate with a port number through which it will be able to communicate with the other end of the connection.4 SIGNALS Signals inform processes of the occurrence of asynchronous events. Each socket supports a particular type of networking specified when the socket is created. The most common types are. 5. Creating a socket returns a socket descriptor which is needed for establishing a connection. Socket is an end point abstraction of a network connection. A socket is an end point for communication in an application program. Processes may send each other signals through the KILL system call.  Signals having to do with the processes that cause exceptions.

function is the address of the user function the process wants to invoke on receipt of the signal and the return value oldfunction is the value of function in the most recently specified call to signal for signum. If a process receives a hang-up signal and a kill signal it sets the corresponding bits in the process table signal field but it can‟t remember how many instances of the signals it receives.function) Where signum is the signal number the process is specifying the action for.  Signals for tracing execution of process. 5. But a process can specify a special action to take on receipt of certain signals with the signal system call The syntax for the signal system call Oldfunction=signal (signum. A process can remember different type of signals but it has no memory of how many signals it receives of a particular type.1 HANDLING SIGNALS There are three cases for handling signals via.  Process exits on receipt of the signal  Process can ignore the signal  Process executes a particular function on the receipt of the signal The default action is to call exit in kernel mode. Signals originating from a process that receives an alarm signal after an interval of time. To send a signal to a process the kernel sets a bit in the signal field of the process table entry corresponding to the type of the signal. .4.

Chapter 6 PROJECT DESCRIPTION .

which can be reduced by sending the signal after 100 bytes. If the request is for file transfer the child. At most. Once the parent receives this signal it sends a signal to all the processes in its group. So when the main server crashes during the file transfer. The child process receives the request from the corresponding client and processes it. process checks whether the file exists or not. The child processes on receiving the signal from the parent process write their corresponding status into the pipe one by one. PROJECT DESCRIPTION 6. The parent process creates a child process for each of the client logged in. the child process opens the file. The parent process also receives this signal and on receiving it waits at the end of the unnamed pipe created by the parent process itself. The parent process then reads from the piped one by one and sends them to the alternate server.1 MAIN SERVER The main server first changes its process group id in order to send signals to all the child processes. For every thousand bytes sent. reads the content of the file and transfers them to the client. there will be a redundancy of thousand bytes.6. Then it calls the set timer function to initiate timer so that it sends the SIGNALRM at regular intervals. It checks whether request is for file transfer or for message transfer. the alternate server resumes the file transfer by reading the status. If the file exists. . the main server sends a signal to the alternate server.

. The Alternate Server receives the status of the main server and updates the information in a separate file. the clients will connect to the port number and IP address to which the alternate server is bound. Once the main server crashes. The alternate server then resumes the operations for each of the clients at the stage where they were interrupted when the main server crashed. This host termed as the Alternate Server is dedicated solely to this particular main server.2 ALTERNATIVE SERVER In this proposed system the alternate server takes the role of a backup to the main server. the status of its operations with each of its clients at regular intervals. This is how the main server distinguishes the Alternate Server from the rest of its clients.6.e. The clients are not aware of the fact that an alternate server exists. In addition to being the first client of the main server. The alternate server will be the „first‟ client to connect to the main server. The server performs its bookkeeping operations by constantly sending the Alternate Server of its status i. So the alternate server is bound to another port number and IP address where it listens for the clients to connect to it. it connects to the appropriate port number of the main server. As the operations carried out by the main server (File Transfer & Message Transfer) are of utmost importance and its crashing may cause serious problems the server engages a separate host to act as its backup. Initially when a client wants to log on to the main server. the alternate server should also act as the server for the clients as soon as the main server crashes. The interval can be set to any desired value.

all the clients connect to the alternate server. when a new client tries to log to the main server. the alternate server will be able to accept any new client which connects for request. Before connecting the value of the port number and IP address are modified to that of the alternate server.3 CLIENT The client performs normal transaction with the main server until it crashes.4 STRUCTURES USED 6.4.1 PREDEFINED STRUCTURES  Socket address structure „SOCKADDR_IN‟ This structure is defined in <sys/socket.After the server crash. 6.h>. /*AF_INET*/ /*16-bit port no. u_short sin_port. On file crash. struct in_addr sin_addr. 6. the client host will connect to the alternate server only.. This value for this structure is value as soon as the connection is established. network byte ordered*/ . The user who is logged as the client will not be aware of this fact. network byte ordered*/ /*32-bit host id. Moreover. The alternate server may continue to process the clients requests till the main server restarts after which the clients may connect to the main server once again. struct sockaddr_in { short sin_family.

strcut timeval it_value. This structure is contained in <sys/time. }. }.h> struct itimerval { struct timeval it_interval. struct timeval { long tv_sec. /*unused*/  Timer structure „ITIMERVAL‟. /*seconds*/ /*microseconds*/ /*next value*/ /*current value*/ . long tvusec. }.char sin_zero[8].

int bytes. char mess[50]. of bytes transferred*/ /*identifies file transfer/message transfer */ /*file name of transferring file (m=‟f‟)*/ /*message being transferred (m=‟c‟)*/ . This structure is used to send the status of all the clients to the alternate server.2 USER DEFINED STRUCTURES  Server status attributes „SERVSTAT‟. } /*child identifies*/ /*no.6. char file[20].4. struct servstat { int ch. char m.

TXT” This file contains the list of names of all the clients who have been logged in and is maintained by the main server. When a new client logs in the server gets the name from the client and checks it with the list of name in this file.  “CLILIST1. .5 FILE HANDLING LIST OF FILES  “CLILIST.TXT” This file is used by the alternate server and it contains the status of the main server when the last signal was received from the main server.6. The alternate server also follows the same process of login for the clients. Then the server makes entry of the name.TXT” This file is used by the alternate server and it contains the list of names of all the clients who have logged on to the main server. This continues until the client sends a new name. If the name already exists then the server asks the client to send a new name. The alternate server updates the contents of this file every time on the receipt of the status information from the main server. In addition to this the file also contains the list of client names who have logged after the crash. When the main server crashes the alternate server uses the information contained in this file to resume the operations uncompleted by the main server.  “STATUS.

 clistat () This function is invoked by each of the child process pertaining to each of the client. The child process corresponding to the sender writes the message in to the pipe. This function performs the operation of obtaining the status of the client with the main server and sends each of the status to the alternate server.  Fork() A fork ( ) creates a child process that differs from the parent process only in its PID and PPID.5.  Msg () This function is used by the parent process to transfer the message sent by one client to the destination client.C  Alterstat () This function is invoked by the parent process of the main server every t secs.6.1 FUNCTIONS USED  SERVER. Through this function each of the clients sends its status to the parent process of the main server. This function is invoked every time alterstat () is invoked. and in the fact that resource utilizations are set to 0. . The parent process gets the message from the pipe and transfers it to the destination client.

 associate() This function is used by the client to connect to the main server. . Here the IP address and the port number are assigned to that of the alternate server. This function is invoked every time alterstat () is invoked. Here the IP address and the port number are modified to that of the alternate server. The parent process gets the message from the pipe and transfers it to the destination client. This function gets invoked when the main server crashes.  CLIENT. This function is invoked initially when the client wants to log on to the main server. ALTERSERVER.C  new() This function is used by the client to connect to the alternate server. Through this function each of the clients sends its status to the parent process of the main server.C  Clistat () This function is invoked by each of the child process pertaining to each of the client.  msg () This function is used by the parent process to transfer the message sent by one client to the destination client. The child process corresponding to the sender writes the message in to the pipe.

then the process is terminated Stop the process after the signal is received . A Signal can also be come directly from the OS kernel when a hardware event such as a bus error or an illegal instruction is encountered. Signals can be posted to a process when the system detects a software event. Signals are software generated interrupts that are sent to a process when a event happens. C programs (and UNIX) can trap these for diagnostics. Also user specified communication can take place in this way. When a process terminates abnormally it usually tries to send a signal indicating what went wrong. Signals can be synchronously generated by an error in an application. Signal delivery is analogous to hardware interrupts in that a signal can be blocked from being delivered in the future. Some signals stop the receiving process and other signals can be ignored. The system defines a set of signals that can be posted to a process. but most signals are asynchronous.6 SIGNALS: <signal. Most signals cause termination of the receiving process if no action is taken by the process in response to the signal.h> In this section will look at ways in which two processes can communicate. such as a user entering an interrupt or stop or a kill request from another process. such as SIGFPE and SIGSEGV.6. Each signal has a default action which is one of the following:     The signal is discarded after being received The process is terminated after the signal is received A core file is written.

.h> header file for common signals.Each signal defined by the system falls into one of five classes:      Hardware conditions Software conditions Input/output notification Process control Resource control Macros are defined in <signal. These include: SIGHUP 1 /* hang up */ SIGQUIT 3 /* quit */ SIGABRT 6 /* used by abort */ SIGALRM 14 /* alarm clock */ SIGCONT 19 /* continue a stopped process */ SIGCHLD 20 /* to parent on child stop or exit */ SIGINT 2 /* interrupt */ SIGILL 4 /* illegal instruction */ SIGKILL 9 /* hard kill */ Tab 1.1 Macro signals Signals can be numbered from 0 to 31.

For example kill(getpid().kill(). There is also a UNIX command called kill that can be used to send signals from the command line . If pid is greater than zero. the signal is sent to all processes. Only processes with certain access privileges can be killed off. Therefore protection is built into the system.a system call that send a signal to a process. except system processes. The SIGKILL signal cannot be caught or ignored and will always terminate a process. -1 otherwise and sets errno accordingly. would send the interrupt signal to the id of the calling process. Basic rule: only processes that have the same user can send/receive messages. . If pid is 0. int raise(int sig) sends the signal sig to the executing program. the signal is sent to the process whose process ID is equal to pid. raise() actually uses kill() to send the signal to the executing program: kill(getpid(). NOTE: that unless caught or ignored.see man pages. kill() returns 0 for a successful call. pid. int signal) .SIGINT). sig). the kill signal terminates the process.Sending Signals -. raise() There are two common functions used to send signals int kill(int pid.

This can be changed on a per-signal basis so that a signal handler executes on a special stack. This lets the signal handler return to the point that execution was interrupted in the process. it must restore the previous context itself Receiving signals is straighforward with the function: int (*signal(int sig. unsigned int alarm(unsigned int seconds) -. When a signal handler is invoked on receipt of a signal.signal() An application program can specify a function called a signal handler to be invoked when a specific signal is received.This would have a similar effect to exit() command.that is to say the function signal() will call the func functions if the process receives a signal . If a process must resume in a different context than the interrupted one. Also ctrl-c typed from the command sends a SIGINT to the process currently being. it is said to catch the signal. Signal Handling -. Signal handlers usually execute on the current stack of the process. void (*func)()))() -.sends the signal SIGALRM to the invoking process after seconds seconds. A process can deal with a signal in one of the following ways:    The process can let the default action happen The process can block the signal (some signals cannot be ignored) the process can catch the signal with a handler.

we could do: signal(SIGINT. SIG_IGN -. which will terminate the process upon receipt of sig. . Thus to ignore a ctrl-c command from the command line. we would do: signal(SIGINT. SIG_DFL). func() can have three values: SIG_DFL -. TO reset system so that SIGINT causes a termination at any place in our program. SIG_IGN). Signal returns a pointer to function func if successful or it returns an error to errno and -1 otherwise.a pointer to system ignore function SIG_IGN() which will disregard the sig action (UNLESS it is SIGKILL).a user specified function.a pointer to a system default function SID_DFL().h (standard library) header file. A function address -. SIG_DFL and SIG_IGN are defined in signal.sig.

During this time no other clients are serviced. The problem with an interactive server is when step 2 takes a while. and connect that user to the server. Wait for a client request to arrive. An iterative server iterates through the following steps. The purpose of the application is for the server to provide some defined service for clients. Process the client request. Send the response back to the client that sent the request. either simultaneously. A concurrent server. Most networking applications are written assuming one side is the client and the other the server.7 Client-Server model The client-server model is used to divide the work of Internet programs into two parts. although it might talk to several servers. 4. There are other such complex possibilities. but we will discuss only clients that talk to a single server. . 1. This part is called the Server. a Client talks to a single user at a time. We can categorize servers into two classes: iterative or concurrent. or one after the other (the server designer decides upon that). performs the following steps. This part is called the Client. One server may give service to many different clients. 3. The other part knows how to talk to a user. or to give a certain service. if its nature requires that. On the other hand. Go back to step 1.6. 2. on the other hand. One part knows how to do a certain task.

Start a new server to handle this client's request. and concentrate on the networking part. The advantage of a concurrent server is that the server just spawns other servers to handle the client requests. We will leave this to someone else to explain. How this step is performed depends on the operating system. and show them to the user. 2. task. When complete. multiple clients are serviced concurrently 6. This time. and hidden from the user.1 Roles of Clients A client's main feature is giving a convenient User interface.7. Some of the messages will be dealt with by the client automatically. After the connection is established. The Client needs to be able to do two things: 1. The client needs to first establish a connection with the server. translate them to the server's language (protocol) and send them to the server.Wait for a client request to arrive. pop-up-menus and other such fancy stuff. people are trying to write mostly graphical clients. its own server. using windows. or thread. This new server handles this client's entire request. This may involve creating a new process. the Client designer's choice. 1. this new server terminates. Assuming the operating system allows multi-programming. in essence. translate them into human-readable form. 2. Today. given it's address. Receive messages from the server. Receive commands from the user. Go back to step 1. Each client has. depending on what the underlying operating system supports. . hiding the details of how the server 'talks' from the user.

We will discuss two kinds of servers:  Single-client server.7. .This forms the basic loop a client performs: get the server's address form a working address that can be used to talk over Internet.2Roles of Servers A server main feature is to accept requests from clients. connect to the server while (not finished) do: wait until there's either information from the server. If (information from server) do parse information show to user. handle them. update local state information. done 6. and  Multi-client server. or from the user. etc. or deal with locally. and send the results back to the clients. else {we've got a user command} parse command send to server.

Accept connection requests from a Client. so Clients will be able to connect forever do: listen on the port for connection requests. This forms the main loop a Single-Client Server performs: bind a port on the computer. or error messages done else abort the connection done . 3. 2. Close the connection when done. accept an incoming connection request if (this is an authorized Client) while (connection still alive) do: receive request from client handle request send results of request. Receive requests from the Client and return results. or clear it if it's broken from some reason.Single Client Servers These are servers that talk to a single client at a time. They need to be able to: 1.

This forms the main loop a Multi-Client Server performs: bind a port on the computer. They need to be able to: 1. Accept new connection requests from Clients.7. or error messages done .3 Multi Client Servers These are servers that talk to a several Clients at the same time.6. so Clients will be able to connect listen on the port for connection requests. forever do: wait for either new connection requests. if (this is a new connection request) accept connection if (this is an un-authorized Client) close the connection else if (this is a connection close request) close the connection else { this is a request from an existing Client connection} receive request from client handle request send results of request. 3. or requests from existing Clients. Close any connection that the client wants to end. Receive requests from any Client and return results. 2.

Chapter 7 TESTING & IMPLEMENTATION .

Unit testing is essentially for verification of the code produced during the coding phase. This testing activity can be considered as testing the design. All the modules are combined and tested as a whole. In this. Unit testing otherwise known as module testing and this testing ensures that each module is working satisfactory as regarded to the expected output from the module. done by the programmer of the module. It has enormous responsibility of detecting any type of error that may occur in the software. This testing is the systematic testing for constructing the program structure. and hence the goal is to test the internal logic of the modules. while at the same time conducting test to uncover efforts associated with the interface. The various levels of testing are. different modules are tested against the specifications produced during design for the modules. .  Unit Testing  system Testing UNIT TESTING The first level of testing is unit testing.7. The unreliability of the quality assurances activities in the early part of the development cycle which is based on human evaluation place a very high responsibility on testing. TESTING AND IMPLEMENTATION The main purpose of testing is to identify and correct errors in the candidate system. Hence the emphasis is on testing interface between module. It is typically. Testing is the last phase before the final software is delivered.

The reference document for this process is the requirement document. This testing includes forced system failure and validation of the total system as it will be implemented by the user in the operational environment. Conversion which is a changing from one system to another is one aspects of the implementation. IMPLEMENTATION Implementation is the process of converting the new or revised system design in to an operational one. Generally. and the goal is to see if the software meets its requirement. risks. The other aspects are the post implementation review and software maintenance. The objective here is to put the tested system in to operation while holding costs. . and personnel irritation to a minimum.SYSTEM TESTING The system Testing is designed to uncover weakness that were not found in earlier tests. it begins with the low volumes of transactions based on live data.

Chapter 8 CONCLUSION .

The maintenance of the client information and the status of the file transfer are done by the server. The project supports the client server model by sending the signals as messages and initiates the servers working. CONCLUSION The project is fulfilled all the requirements and hope that it helps NetworkOriented programmers to better the implementation in practical. primarily in the Client-Server model.8. The alternate server takes the back up of the main server and transfers the file. Some possible future work may be to improve with Multiple Server-Client model and thus apply our project to Network applications . The project is very much useful for system administrators to analyze the Network bottleneck. The project is developed with network as backbone. so that it is very useful for the network administrators.

Chapter 9 FUTURE ENHANCEMENT .

. The additional implementation in this project may include message transfer. bulk of files and even all the network transferring functions. In future use the project succeeds with the multiple clients and reduces the problem of redundancy. FUTURE ENHANCEMENT The project supports multiple clients with the enrichment of alternate server and thus increases the efficiency of the file transfer between client and server. It fulfills all the client requirements and results in the efficient file transfer.9.

Chapter 10 REFERENCES .

bell-labs. Murray Hill.Bach.Richard Stevens. 6.oreilly. 5. Advanced Programming in the UNIX Environment by W. Khan. UNIX for Programmers & the User by Graham Glass and King Ables.pdf . 7.Raymond. New Jersey. 2. The UNIX System Programming By Kay A. UNIX Network Programming by W. Bell Laboratories. Prentice Hall of India Pvt. 8. REFERENCE 1. The UNIX Programming Skills by Rob Pike.Richard Stevens.html http://www. process.maclab. The UNIX Programming Environment by Brian W.uchicago.10. Maurice J. New Jersey.com/cm/cs/who/dmr/hist. Bell Laboratories. Murray Hill. 9. WEB REFERENCE http://www. The Art of UNIX Programming by Eric S. The Design of the UNIX Operating System. Chapter 6&7. Ltd. 3.html http://cm.cs. Robbins and Steven Robbins. 4. Practical UNIX Programming by Ashfaq A.com/openbook/freedom/index.Kernighan.edu/tutorials/unix tutorial/unix.

CHAPTER 11 APPENDIX .

h> #include <signal. char mess[50].h> #include<netinet/in. which same structure but different name*/ struct sockaddr_in my_addr.h> #include<sys/ipc. /* I need call a sub function and pass the value in my_addr to the subfunction.s2. like pid_t */ /* standard I/O functions */ .h> #include<sys/shm.h> int pa[2]. */ /* various type definitions. char m.ch1[2]. struct pi { int h.h> #include<stdlib. and the kill() prototype */ /* standard unix functions. like getpid() */ /* common system V IPC structures.i. int d.11.h> #include<string. struct sockaddr_in cli_addr.h> #include <unistd. APPENDIX SIGN.h> #include<sys/types. void sig() /* signal handler*/ /*structure for writing and reading pipes*/ /* signal name macros.C #include<stdio.their_addr.h> #include<sys/socket.ns[20]. char st[2]. char file[20]. }h1.

SOCK_STREAM. their_addr.&port). my_addr.h1. signal(3. mys1=socket(AF_INET.0.s_addr=inet_addr("127.sin_addr.sin_family=AF_INET. signal(3.SOCK_STREAM.0).0. } pipe(pa).sizeof(their_addr)).(struct sockaddr *)&(my_addr).mess.sin_family=AF_INET. s2=send(h1.sig).sizeof(h1)).h. read(pa[0]. my_addr. ss=sizeof(cli_addr).mess.h. s2=send(h1.{ ch1[0]='b'. bzero(&(their_addr).&h1.s_addr=inet_addr("127.0.s2). printf("signal\n").sin_addr.h1.mess). bind(mys. my_addr.5).sizeof(my_addr)).sin_port=htons(4350). scanf("%d". their_addr.0).0.s2).h1.sin_port=htons(port). their_addr. listen(mys.2. if(fork()==0) { printf("enter the port no").0). printf("%d\n". /*to handle signals from child processes*/ i=1.2").ch1. printf("%d\n".h). /*pipe created*/ mys=socket(AF_INET. printf("%s %d\n". .sig).5").0).sizeof(h1.

printf("%d\n".1. if(h1.h1. f++."w").d). while(strcmp(h1."child")=='###BOT_TEXT###') { strcpy(chumma.sizeof(str2). } if(ch1[0]=='f') { recv(mys1. strcat(name.txt".0)."r").&h1.read(mys1.sizeof(their_addr))==-1) { perror("not connected\n").sizeof(str2).txt". exit(0). } if(fork()==0) /*client handler--clild process*/ { if(strstr(name."child").d) printf("%d\n".str2.f2).sizeof(struct pi)."statusover")!=0) { printf("%c\n".m).1. .sizeof(str2). } f2=fopen("clilist1. f2=fopen("clilist1.h1.(struct sockaddr *)&(their_addr).txt".name).sizeof(struct pi))). read(mys1."w").mess. while(!feof(f2)) { ch=fgetc(f2).str2.sizeof(struct pi)). while(strcmp(str2. if(ch=='\n') { fname1[k]='###BOT_TEXT###'."fileover")!=0) { fwrite(str2. fwrite(&h1.f2). } if(ch1[0]=='c') { f2=fopen("status.&h1.0).if(connect(mys1. recv(mys1.

} while(str[j++]!='@'). printf("%s\n". exit(0). k=0. while(!feof(f2)) {printf("%s\n". f2=fopen("clilist1.txt".0)./*parse the message to find the destination client name*/ k=0.sizeof(str). if(!strcmp(str."r")./*signal to the parent to send the message to destination*/ flag1=0."exit")) { ch2[0]='b'. break. k=0. dname[k]='###BOT_TEXT###'.0). ch=fgetc(f2)."child")."found").ch2. f++. while(str[j]!='@') dname[k++]=str[j++].3). break. } .inc++.dname). send(z1.k=0. inc++.2. } write(pa[1]. if(!strcmp(fname1.str. inc=-1. if(ch=='\n') { fname1[k]='###BOT_TEXT###'. strcat(dname. if(!strcmp(fname1.dname)) {printf("%s\n"."readfile").sizeof(h1)). /*writing into pipe the client no*/ /*client exits*/ kill(getppid(). send(z1.&h1.name)) { flag1=1. flag1=1.

s_addr=inet_addr("127. FILE *f1.h> #include<sys/types.name[20].h> struct sockaddr_in theiraddr. char st[2].p=0.h> #include <unistd.retval. and the kill() prototype */ /* standard unix functions. theiraddr.ch1[2].name.C #include<stdio.sercnt=0.sizeof(name).sizeof(theiraddr)).0.sizeof(theiraddr))==-1) recv(mys.ch[2].aut[5].retval1.sin_family=AF_INET. void associate().0.port. like pid_t /* common system V IPC structures.5"). void new() { mys=socket(AF_INET.(struct sockaddr*)&theiraddr.CLIENT.fname[20].s1.name1[20].sin_addr.semid.0). bzero(&theiraddr. theiraddr. /* various type definitions. int mys. void connection().h> #include<sys/sem.str[50].dname[20]. like getpid() */ */ /* standard I/O functions . theiraddr.pid.sin_port=htons(4350). */ /* signal name macros.fmess[ 50].h> */ #include<sys/socket.SOCK_STREAM.0).h> #include <signal.h> #include<sys/ipc. if(connect(mys.h> #include<fcntl.

0).sizeof(theiraddr))==-1) { mys=socket(AF_INET. connection().SOCK_STREAM.0. scanf("%s".sizeof(theiraddr)).0.name).sin_family=AF_INET. associate(). theiraddr. send(mys. theiraddr."new". send(mys. goto q.sizeof(theiraddr)).0).0666|IPC_CREAT). theiraddr.if(p==1) { strcat(name1.0.0.sin_port=htons(port).name1.0).name1.1.5"). bzero(&theiraddr. theiraddr. } else { while(1) { if(sercnt==0) { printf("enter ur name\n").sizeof(name1).(struct sockaddr*)&theiraddr. bzero(&theiraddr.SOCK_STREAM. signal(5. } void connection() { q:if(connect(mys. signal(5.sin_family=AF_INET.sizeof(name1).s_addr=inet_addr("127. } else send(mys.s_addr=inet_addr("127.sin_port=htons(4350).sin_addr.0). } main() { semid=semget(0x20.2"). theiraddr. theiraddr.new)."child").sin_addr.0). . } void associate() { mys=socket(AF_INET.new).sizeof("new").

sizeof(name1).0).SETVAL. strcpy(name1.sizeof(aut).0)!=1)."fileover")!=0) } .SETVAL.GETVAL. new().0).0)!=0).GETVAL.1). } pid=fork().aut.1).name1. semctl(semid. if(pid!=0) { while(1) { semctl(semid. strcpy(fname. while(semctl(semid. kill(getppid().0)!=0). while(semctl(semid. if(s1==0) { perror("Connect to alternate server\n").0)."###BOT_TEXT###").0. semctl(semid. if(ntohs(theiraddr."ac")) break."w").5).0. if(!strcmp(aut.sin_port)==4000) strcat(name. s1=recv(mys.SETVAL.fmess. f1=fopen(dname. } if(ch1[0]=='a') { while(semctl(semid."child").recv(mys.GETVAL.name).0.0.0. else continue. } recv(mys.GETVAL. while(semctl(semid.sizeof(name). while(strcmp(fmess.0.name.0). printf("%s\n".0).0)!=1). send(mys.0.aut).sizeof(fmess).

}h1.h> #include <unistd.i. char mess[50]. char file[20]. like getpid() */ /* standard I/O functions .semid.h> */ #include <signal.name[20]. char ch1[2].h> #include<sys/sem.ch1. void al() { ch1[0]='c'. } struct pi { int h. struct itimerval value.s2.ns[20].sig1). signal(SIGALRM.ALTER.g. send(ns[1].cnt. void sig1() /*structure for writing and reading pipes*/ { kill(0.h> #include<sys/time.x.2).x1. while(cnt!=i-2) /* signal name macros.h> int pa[2]. struct itimerval ovalue. int d.2. struct sockaddr_in cli_addr. char m.c.C #include<stdio.0). struct sockaddr_in my_addr.fcnt=0. and the kill() prototype */ /* standard unix functions.

} strcpy(h1.0). } void si() { if(i!=1) { if(g==1) h1. else h1.fname1[20].d=x1.sl.ch2[2].mess)."empty").ch1.h=i.port. strcpy(h1.ns[h1.flag=0.al).j=0. strcpy(h1. /* signal handler*/ . signal(2.ch.name). s2=send(ns[h1. s2=send(ns[h1.ft[20]. int mys.{ read(pa[0].m=c. printf("%s %d\n". cnt++.&h1. } main() { setpgrp().sizeof(h1)).dname[50].2.h]. h1. semid=semget(0x30.0666|IPC_CREAT).1.&h1.z.k=0. write(ns[1].d=0.SETVAL. semctl(semid. read(pa[0]. } void sig() { ch1[0]='b'.&h1.h1.sizeof(struct pi)).inc=0.mess.str1[20].*f3.sizeof(h1)).0.*f2.flag1=0.mess.h]).sizeof(h1.f=0.fmess[50]="###BOT_TEXT###". printf("signal\n"). h1.0). FILE *f1. cnt=0.ss.mess[50].mess.h1.0).file.h]. char str[50].a lt[20].mess."statusover").

"ac". value. z=ns[i].tv_sec=0. send(z.(struct sockaddr *)&(my_addr). my_addr.tv_sec=25.0). if(flag==1) { send(z."binded").al). signal(3. bind(mys.sin_addr. if(i!=1) { while(1) { recv(z.it_value.txt". ovalue. my_addr. mys=socket(AF_INET.sig). listen(mys.it_value.sizeof(my_addr)).sizeof(my_addr)). scanf("%d". } else { send(z.pipe(pa).(struct itimerval*)&ovalue)."r"). while(1) printf("%d\n".sin_port=htons(port).0.ns[i]).0).5. value.str1. ss=sizeof(cli_addr).0).0).s_addr=inet_addr("127. printf("%s\n". /*pipe created*/ printf("enter the port\n").0).sin_family=AF_INET.tv_sec=25.SOCK_STREAM.&port).5).(const struct itimerval*)&value.sizeof(str1).sizeof(str1).5."al". signal(2. my_addr.str1.it_interval.0). strcpy(name. setitimer(ITIMER_REAL. bzero(&(my_addr). f1=fopen("clilist.2"). /*name already exists*/ /*name authenticated*/ /*to check for name validity*/ .str1).sig1).sizeof(str1). recv(z.0. /*to handle signals from child processes*/ signal(SIGALRM.str1.

fputs(str1. signal(2.ch2./*signal to the parent to send the message to destination*/ } /*client exits*/ /*client handler--clild process*/ . k=0. } dname[k]='###BOT_TEXT###'.SIGALRM). write(pa[1].str. } if(!strcmp(str. if(fork()==0) { fcnt++. kill(getppid(). exit(0).1).f1).txt". semctl(semid. f2=fopen("clilist.0.&h1.f1). fputc('\n'.sizeof(h1)).si).0).0). send(z.sizeof(str).} while(str[j++]!='@')."r"). while(!feof(f3)) { if((fcnt%20)==0) { x1=fcnt.txt"."a")."exit")) { ch2[0]='b'. while(1) { fcnt=0. send(z.2.3).f1=fopen("clilist. c='n'. /*writing into pipe the client no*/ kill(getppid()./*parse the message to find the destination clientname*/ k=0. while(str[j]!='@') { dname[k++]=str[j++]. g=1.SETVAL.

SCREEN SHOTS .2.11.