diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6b468b6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.class diff --git a/bin/j2/WRNet.class b/bin/j2/WRNet.class deleted file mode 100644 index 27b3411..0000000 --- a/bin/j2/WRNet.class +++ /dev/null Binary files differ diff --git a/src/j2/Telnet.java b/src/j2/Telnet.java new file mode 100644 index 0000000..9cfdc3a --- /dev/null +++ b/src/j2/Telnet.java @@ -0,0 +1,66 @@ +package j2; + +// Telnet.java +// ネットワーク上のサーバに接続し,データを送ります +// その後サーバからデータを受け取り,そのまま画面に出力します +// 使い方 java Telnet host名 ポート番号 +// 例 java Telnet localhost 8000 + +//ライブラリの利用 +import java.io.InputStream; +import java.io.OutputStream; +import java.net.Socket; + +// Telnetクラス +public class Telnet { + // プログラムの本体main + public static void main(String[] args){ + byte[] buff = new byte[1024];//配列の定義 + Socket wrsocket = null ;// サーバ接続用ソケット + InputStream instr = null;// データ読み取り用オブジェクト + OutputStream outstr = null;// データ出力用オブジェクト + boolean cont = true ; + // 指定のポートに対して,ソケットを作成します + // 入出力のストリームを作り,データ読み出しを準備します + try{ + wrsocket + = new Socket(args[0],Integer.parseInt(args[1])) ; + instr = wrsocket.getInputStream() ; + outstr = wrsocket.getOutputStream() ; + } catch (Exception e) { + System.err.println("Network error.") ; + System.exit(1) ; + } + // + while (cont) { + try { + int n = System.in.read(buff); + if(buff[0] == '.') cont = false ; + else outstr.write(buff,0,n) ; + } + // 以下は例外処理です + catch(Exception e){ + // 例外時はプログラムを終了します + System.exit(1); + } + } + // データの終了まで,以下のループを繰り返します + cont = true ; + while (cont) { + try { + int n = instr.read(buff); + System.out.write(buff, 0, n) ; + } + catch(Exception e){ + // 読み出し終了時にループも終了 + cont = false ; + } + } + try { + instr.close() ; + } catch(Exception e) { + System.err.println("Close failed.") ; + System.exit(1) ; + } + } +} diff --git a/src/j2/WRNet.java b/src/j2/WRNet.java deleted file mode 100644 index c74d5ad..0000000 --- a/src/j2/WRNet.java +++ /dev/null @@ -1,66 +0,0 @@ -package j2; - -// WRNet.java -// ネットワーク上のサーバに接続し,データを送ります -// その後サーバからデータを受け取り,そのまま画面に出力します -// 使い方 java WRNet DNS名 ポート番号 -// 例 java WRNet localhost 8000 - -//ライブラリの利用 -import java.io.InputStream; -import java.io.OutputStream; -import java.net.Socket; - -// Wrnetクラス -public class WRNet { - // プログラムの本体main - public static void main(String[] args){ - byte[] buff = new byte[1024];//配列の定義 - Socket wrsocket = null ;// サーバ接続用ソケット - InputStream instr = null;// データ読み取り用オブジェクト - OutputStream outstr = null;// データ出力用オブジェクト - boolean cont = true ; - // 指定のポートに対して,ソケットを作成します - // 入出力のストリームを作り,データ読み出しを準備します - try{ - wrsocket - = new Socket(args[0],Integer.parseInt(args[1])) ; - instr = wrsocket.getInputStream() ; - outstr = wrsocket.getOutputStream() ; - } catch (Exception e) { - System.err.println("Network error.") ; - System.exit(1) ; - } - // - while (cont) { - try { - int n = System.in.read(buff); - if(buff[0] == '.') cont = false ; - else outstr.write(buff,0,n) ; - } - // 以下は例外処理です - catch(Exception e){ - // 例外時はプログラムを終了します - System.exit(1); - } - } - // データの終了まで,以下のループを繰り返します - cont = true ; - while (cont) { - try { - int n = instr.read(buff); - System.out.write(buff, 0, n) ; - } - catch(Exception e){ - // 読み出し終了時にループも終了 - cont = false ; - } - } - try { - instr.close() ; - } catch(Exception e) { - System.err.println("Close failed.") ; - System.exit(1) ; - } - } -} diff --git a/src/run2-3.sh b/src/run2-3.sh index 5b016a2..c33a0c8 100755 --- a/src/run2-3.sh +++ b/src/run2-3.sh @@ -2,10 +2,10 @@ javac -encoding UTF-8 j2/*.java -echo "Now, open other terminal, and run EchoClient" -echo ">>>> $ java j2/EchoClient"; +echo "Now, open other terminal, and run Telnet(Java) +echo ">>>> $ java j2/Telnet localhost 8000"; echo " ^^^^^^^^^^^^^^^"; -echo "start EchoServer" +echo "start Phttpd" java j2/Phttpd j2/Phttpd.java #echo "type return to exit"