import jp.jbxl.*;

class TCP_C_0
{
   public static void  main(String args[])
   {
       int port = 80;
       String coding = "UTF-8";

       if (args.length<1) {
           System.err.printf("usage... java TCP_C_0 hostname [port] [encoding]\n");
           System.exit(1);
       }
       String hostname = args[0];
       if (args.length>1) port = Integer.parseInt(args[1]);
       if (args.length>2) coding = args[2];

       //
       TCP_Socket tcp = new TCP_Socket(hostname, port, coding);

       String recv = "";
       try {
           tcp.sendMesg("GET / HTTP/1.0\r\n\r\n");

           recv = tcp.recvMesg();
           while(recv!=null) {
               System.out.println(recv);
               recv = tcp.recvMesg();
           }
       }
       catch (Exception er) {
           er.printStackTrace();
           System.err.printf("disconnected!\n");
       }
       tcp.close();
   }
}
最後修改: 2023年 12月 20日(週三) 17:53