\documentstyle[12pt]{article}
\setlength{\topmargin}{-0.6in}		%for dvi-imagen
\setlength{\oddsidemargin}{0.1in}   	%prev:-0.1 for dvi-imagen, -ve needed.
\setlength{\headheight}{.3in}
\setlength{\headsep}{.3in}
\setlength{\textheight}{9.0in}
\setlength{\textwidth}{6.6in} 
\setlength{\marginparwidth}{0in}
\setlength{\marginparsep}{0in}
\setlength{\marginparpush}{0in}
\setcounter{secnumdepth}{2}	%to get numbers on subsubsection in text
\setlength{\oddsidemargin}{0.1in}   	%prev:-0.1 for dvi-imagen, -ve needed.
\setlength{\headheight}{.3in}
\setlength{\headsep}{.3in}
\setlength{\textheight}{8.8in}
\setlength{\textwidth}{6.4in} 
\setlength{\marginparwidth}{0in}
\setlength{\marginparsep}{0in}
\setlength{\marginparpush}{0in}
\setcounter{secnumdepth}{2}	%to get numbers on subsubsection in text
				%default is 2.
\setcounter{tocdepth}{2}	%to get numbers on subsubsection in toc
				%default is 2.
\setlength{\unitlength}{1mm}
\newfont{\bi}{cmbxti10 scaled\magstep1}       % Bold Italics(12pt) 
\renewcommand{\baselinestretch}{1.2}  % 1.6 for kind of double spacing
\setlength{\parindent}{0.2in} %JUST CHANGED FROM 0.2
\input{psfig}
\newcommand{\Settab}
   {***\=***\=***\=***\=***\=***\=***\=***\=***\=***\=***\=***\= \kill}
\begin{document}
\large
\noindent
{\bf Young-ki Hwang}\\
{\bf youngki@top.cis.syr.edu}\\
{\bf April 30. 1996}\\
{\bf project}\\

\normalsize
\tableofcontents

\newpage
\section{Project Description}

\subsection{Title}
Multi-user chat in the internet.

\subsection{Description}
You can use the {\it TALK} program and talk to one person at a time, or you can use {\it YTALK} and talk to one or more people at the same time. What these programs have in common is that your conversation are private , like a telephone call. You control who you talk to and only those people can take part in the conversation. \\
But a vast number of people can gather in one place and talk to every other people in the {\it Multi-User Chat} environment. Whatever you say can be heard by everyone else in your group. You can hear what everyone says.

\newpage
\section{Class Hierachy}

Figure~\ref{fig:class} shows the class hierachy which is used in the project.
\begin {figure}[htbp]
   \centerline{\psfig{figure=class.ps,height=4in,width=5.5in}}
   \caption{class hierachy}
   \label{fig:class}
\end{figure}

\subsection{IPC class}
IPC class is an abstract class that defines communication between processes.
Socket, pipes, signals, forks classes inherit the IPC class.

\subsection{SOCKET class}
Socket is the API(Application Program Interface) to the communication protocol. Socket class defines methods for communication between networks.
\begin{enumerate}
  \item{\bf private data}: socketfd.
  \item{\bf receive(char *buffer)} : Receive data into ``buffer'' from socketfd(private data).
  \item{\bf receive(int sockfd, char *buffer)} : Receive data into ``buffer'' from ``sockfd''.
  \item{\bf send(char *buffer)} : Send ``buffer'' into the socketfd.
  \item{\bf send(int sockfd, char *buffer)} : Send ``buffer'' into the ``sockfd''.
  \item{\bf get\_sockfd()} : Return the socketfd.
  \item{\bf close\_sockfd()} : Close the socketfd.
\end{enumerate}

\subsection{PIPES class}
Pipe is the communication channel between parent and child processes. Pipe class defines methods for communication between parent and child processes.
\begin{enumerate}
  \item{\bf private data}: p[2]. p[0] is for read and p[1] is for write data.
  \item{\bf receive(char *msg, char *id)} : Receive ``msg'' and ``id'' from p[0](private data).
  \item{\bf receive(int rp, char *msg, char *id)} : Receive ``msg''  and ``id'' from ``rp''.
  \item{\bf send(char *msg, char *id)} : Send ``msg'' and ``id'' into  p[1](private data).
  \item{\bf send(int wp,char *msg, char *id)} : Send ``msg'' and ``id'' into  ``wp''.
  \item{\bf send(char *msg)} : Send ``msg'' into  p[1](private data).
  \item{\bf send(int wp ,char *msg)} : Send ``msg'' into  ``wp''.
  \item{\bf get\_readpipe()} : Return the p[0].
  \item{\bf get\_writepipe()} : Return the p[1].
  \item{\bf close\_readpipe()} : Close the p[0].
  \item{\bf close\_writepipe()} : Close the p[1].
\end{enumerate}


\subsection{SIGNALS class}
Signal is a event notification  between  processes. Signals class defines methods for communication between processes.
\begin{enumerate}
  \item{\bf private data}: 
  \item{\bf receive(int sig, void((*func)()))} : When Receiving ``sig'', run the (*func).
  \item{\bf send(int pid, int sig)} : Send ``sig'' to process which is ``pid''.
\end{enumerate}


\subsection{FORKS class}
Fork is only way to make a new process. The fork creates a copy of the process that was executing. The process that exectued the fork is called parent process and the new process is called the child process. Forks class defines how to make a new process.
\begin{enumerate}
  \item{\bf private data}: 
  \item{\bf make\_child()} : Make a new child process.
  \item{\bf wait\_child\_termination()} : Parent process waits until child terminate.
\end{enumerate}


\subsection{SERVER class}
Server class inherits the socket class. Server class defines the methods which should be done in the server part.
\begin{enumerate}
  \item{\bf private data}: newsockfd, server\_address.
  \item{\bf initialize()} : Server register its well-known address with the system. Server port \#, machine address(server\_address) and network protocol type are initialized.
  \item{\bf ready\_connection()} : Make a server to be ready for connection from the client.
  \item{\bf make\_connection()} : Accept a connection from the client.
  \item{\bf get\_newsodkfd()} : Return the newsockfd(private data).
  \item{\bf close\_newsodkfd()} : Close the newsockfd(private data).
\end{enumerate}

\subsection{CLIENT class}
Client class inherits the socket class. Client class defines the methods which should be done in the Client part.
\begin{enumerate}
  \item{\bf private data}: server\_address.
  \item{\bf initialize()} : Client set up the information about the server. Server port \#, server machine address(server\_address) and network protocol type are initialized.
  \item{\bf make\_connection()} : Connect to the server.
  \item{\bf get\_id()} : Get a id of the client.
\end{enumerate}


\subsection{MEMBERS class}
Members class maintain the all the members who are joining currently.
\begin{enumerate}
  \item{\bf private data}: table[].
  \item{\bf insert(char *id)} : Insert a member who is ``id'' into the table.
  \item{\bf remove(char *id)} : Remove a member who is ``id'' from the table.
  \item{\bf Get\_numofmember()} : Return the total \# of members joinging currently.
  \item{\bf Get\_sockfd(char *id)} : Return the sockfd which ``id'' is using.
  \item{\bf Get\_sockfd(int index)} : Return the sockfd which is located in the ``index''th position in the table.
  \item{\bf Get\_readpipe(int index)} : Return the p[0] which is located in the ``index''th position in the table.
  \item{\bf Get\_writepipe(int index)} : Return the p[1] which is located in the ``index''th position in the table.
  \item{\bf check\_exist(char *id)} : Check whether a member who is ``id'' is already exist.
\end{enumerate}

\subsection{STRINGS class}
String class defines methods about manipulating the strings.
\begin{enumerate}
  \item{\bf private data}: 
  \item{\bf copy(char *str1, char *str2)} : Copy ``str2'' to ``str1''.
  \item{\bf compare(char *str1, char *str2)} : Compare ``str2'' with ``str1''.
  \item{\bf scan(char *buf, char *str)} : Get a first string in the ``buf'' into ``str''.
  \item{\bf leftshift(char *str, int count)} : Shift a string to left for ``count'' times.
  \item{\bf concatenate(char *str1, char *str2)} : Concatenate ``str2'' to ``str1''.
\end{enumerate}


\subsection{TERMINAL class}
Terminal class handles the terminal type data, set up the terminal.
\begin{enumerate}
  \item{\bf makeecho()} :  Allow window to echo.
  \item{\bf makenoecho()} : Allow window to noecho.
  \item{\bf makenl()}   : Make window to be nl mode.
  \item{\bf makenonl()} : Make window to be nonl mode.
  \item{\bf makecbreak()} : Make window to be cbreak mode.
  \item{\bf makenocbreak()} : Make window to be nocbreak mode.
  \item{\bf makeraw()}  : Make window to be raw mode.
  \item{\bf makenoraw()}  : Make window to be noraw mode.
  \item{\bf store()}  : Save the terminla type data.
  \item{\bf restore()} : Restore the terminal type data.
\end{enumerate}


\subsection{WINDOW class}
Window class handles the window on the terminal screen.
\begin{enumerate}
   \item{\bf window(int line, int col, int start\_y, int start\_x)} : Make a new window with ``line'' and `''col'' size.
   \item{\bf makescroll()} : Make the window to be scrollable.
   \item{\bf clearall()} : Wipe out the window.
   \item{\bf cleartobottom()} : Wipe out the window fromt the current position to bottom.
   \item{\bf cleartoeol()} : Clear the current line to end of line.
   \item{\bf drawborder(char a, char b)} : Draw the border around the window.
   \item{\bf getstring(char *str)} : Get a string from the window.
   \item{\bf putstring(char *str)} : Put a string onto the window.
   \item{\bf getcharacter()} : Get a character from the window.
   \item{\bf putcharacter(char ch)} : Write a character onto the window.
   \item{\bf deletecharacter()} : Delete a character.
   \item{\bf display()} : Refresh the window.
   \item{\bf destroy()} : Remove a window.
   \item{\bf moveto(int y, int x)} : Move the cusor to (y,x) position on the window.
   \item{\bf get\_cur\_coordinate()} : Get a current cusor position on the window.
\end{enumerate}




\newpage
\section{Algorithm}
\subsection{Process Control}
Figure~\ref{fig:process} shows how to control the processes between server and clients.
\begin {figure}[htbp]
   \centerline{\psfig{figure=process.ps,height=4in,width=5.5in}}
   \caption{Process Control Diagram}
   \label{fig:process}
\end{figure}

When a server receives a connection request from a client, the server accepts it. After then, it forks and makes a new child process. The new child process communicate with the client. Every communication is done between the client and new child process.

\subsection{Data Control}
Figure~\ref{fig:data} shows how to control the data between server and clients.
\begin {figure}[htbp]
   \centerline{\psfig{figure=dataflow.ps,height=4in,width=5.5in}}
   \caption{Dataflow Control Diagram}
   \label{fig:data}
\end{figure}

Client sends  data to server. A child process correspoding to the client gets data, sends it to the parent process. After the parent process gets data from a child process, he sends data to every client who is joining currenltly. The parent process always maintains a list of all members.


          
\newpage
\section{Manual}
\subsection{Server Part}
\begin{enumerate}
   \item Run the server program. You shoul know the IP address of the machine you are using.\\
         prompt \%  irc-server machine\_address\\
         e.g. prompt \%  irc-server 128.230.25.13
\end{enumerate}

\subsection{Client Part}
\begin{enumerate}
   \item Connect to the SERVER machine. You should know the IP address of the server machine.\\
         prompt\% irc-client server\_address\\
         e.g. prompt\% irc-client 128.230.25.13
   \item Enter your ID which you want, if you see following message.\\
         prompt\% Enter your ID :
   \item After get into the Chat program, you will see the following screen.

	Figure~\ref{manual} shows the user interface for client.\\
	\begin{figure}[htbp]
  	\centerline{\psfig{figure=client.ps,height=3in,width=5.5in}}
   	\caption{User Interface of Client}
   	\label{manual}
	\end{figure}
      
        Bottom part of the window is for the input. Top part of the window is for the Chat room.
\end{enumerate}

\subsection{Command}
\begin{enumerate}
   \item {\bf /help} : show the commands.
   \item {\bf /quit} : exit the program.
   \item {\bf /nick new\_name} : Change the current ID to  ``new\_name''.
   \item {\bf /ID message} : Send the following ``message'' only to the person who is ``ID''.
   \item {\bf /ID1/ID2 ... /IDN  message} : Send the following ``message''  to N people who are ID1, ID2 ... , IDN.


\end{enumerate}




\section{Source code}
Please refer to attached source code.
It consists of 3 parts.\\
\begin{itemize}
  \item {\bf Header Files.}\\
        1. ipc.h      : ipc class definition.\\
        2. fork.h     : forks class definition.\\
        3. pipe.h     : pipes class definition.\\
        4. signal.h   : signals class definition.\\
        5. socket.h   : socket class definition.\\
        6. server.h   : server class definition.\\
        7. client.h   : client class definition.\\
        8. terminal.h : terminal class definition.\\
        9. window.h   : window class defintion.\\
        10. member.h  : members class definition.\\
        11. string.h  : strings class definition.\\
   \item {\bf Methods Files.}\\
        1. member.cc : members class methods.\\
        2. client.cc : client class methods.\\
        3. pipe.cc   : pipe class methods.\\
        4. signal.cc : signals class methods.\\
        5. socket.cc : socket class methods.\\
        6. server.cc : server class methods.\\
        7. win.cc    : window class methods.\\
        8. string.cc : strings class methods.\\
    \item {\bf Main Program.}\\
        1. irc-server.cc : main program of server part.\\
        2. irc-client.cc : main program of client part.\\
\end{itemize}
\end{document}










