課題2


課題2:inetdを使用するサーバプログラムの作成
サンプルプログラム(1)はサーバ(server.c)をinetdから起動することで、サーバはクライアント(client.c)の標準入力から入力された文字に対応するキーワードをクライアントに返すプログラムである。サンプルプログラム(1)を自分の実験環境で動作するようにし、実行結果を示すとともに、プログラムの中で使われている関数(Connect,Disconnect, Send Data, Recv Dataなど)の動作を説明し、サーバ・クライアント動作全体をフローを示して説明せよ。

サンプルプログラムを実行する環境にするにはいくつかファイルを変更する必要がある。必要なのは以下の通り ・etcフォルダのservicesにtcpinetd 5682/tcpという文を追加
・etcフォルダのinetd.comにtcpinetd stream tcp nowait root /(絶対パス)/serverを追加(絶対パスはpwdで探す)
・プログラムclient.cとserver.cに#include という文を追加
・rtmp 1/ddp #Routing Table Maintenance Protocol
 tcpmux 1/udp # TCP Port Service Multiplexer
 tcpmux 1/tcp # TCP Port Service Multiplexer
 この3文の頭に#がついていたなら#を消す(コメント扱いなので)
・inetdプロセスを再起動する(アクティビティモニターを使用)
以下は実行結果

j05014@nw0514:nagata1[48] ./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 = xxxx
Keyword = [xxxx] / Data = [yyyy]

Input Keyword = xyz
Keyword = [xyz] / Data = [XYZ]

Input Keyword =
Disocnnected.