課題2:inetdを使用するサーバプログラムの作成
サンプルプログラム(1)はサーバ(server.c)をinetdから起動することで、サーバはクライアント(client.c)の標準入力から入力された文字に対応するキーワードをクライアントに返すプログラムである。サンプルプログラム(1)を自分の実験環境で動作するようにし、実行結果を示すとともに、プログラムの中で使われている関数(Connect,Disconnect, Send Data, Recv Dataなど)の動作を説明し、サーバ・クライアント動作全体をフローを示して説明せよ。
変更点
server.c
・#include < stdlib.h > を追加。
・#define DATAFILE "data"の"data"の部分を"Users/j05059/jikken2/tcpip/data.txt"に変更。
client.c
・#include < stdlib.h > を追加。
・#define HOST_NAME"hoge"の"hoge"の部分を"nw0559.st.ie.u-ryukyu.ac.jp"に変更。
実行結果
17:17:/Users/j05059/jikken2/tcpip:%./client
Connected.
Input Keyword = warning: this program uses gets(), which is unsafe.
yama
Keyword = [yama] / Data = [kawa]
Input Keyword = 123
Keyword = [123] / Data = [456]
Input Keyword = xyz
Keyword = [xyz] / Data = [XYZ]
Input Keyword = abc
Keyword = [abc] / Data = []
Input Keyword =
Disocnnected.
関数の説明
・Conect:socketの生成をして、host nameやhost addressの設定をして、conectionの準備をする関数
・Disconnect:connnectionをcloseする関数
・Send Data:サーバにデータを送る関数
・Recv Data:サーバからデータを受信する関数
・GetLineFromPeer:クライアントからデータを受信する関数
・GetKeywordData:入力された文字列とDataファイルを比較して、ワードを返す関数
全体のフローチャート
もどる