import java.net.*; import java.io.*; class httpapp{ public static void main(String[] args){ String server = "java.ca.nortel.com"; //default httpd server name if(args.length>0) // if httpd host specified on command line. server = args[0] ; int port = 80; //http port BufferedReader disys = new BufferedReader(new InputStreamReader(System.in)) ; System.out.println("\n----- httpapp.class M. Gallant 1/98 ---------") ; System.out.println(" Send an HTTP 1.0 or 1.1 command to a server") ; System.out.println(" Specify the http server as a command line argument") ; System.out.println(" Typical Commands: \"GET /index.html HTTP/1.0\"") ; System.out.println(" \"HEAD /index.html HTTP/1.1\"") ; System.out.println(" \"OPTIONS * HTTP/1.1\"") ; System.out.println("------------------------------------------------------\n") ; String inp = "" ; try{ while((inp = disys.readLine()).length() >0){ Socket socket = new Socket(server,port); //Get a socket, connected to the specified server // on the specified port. BufferedReader inputStream = new BufferedReader(new InputStreamReader( socket.getInputStream())); //Get an input stream from the socket // PrintWriter outputStream = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()),true); DataOutputStream outputStream = new DataOutputStream(socket.getOutputStream()) ; //Get an output stream to the socket. Note // that this stream will autoflush. outputStream.writeBytes(inp+"\r\n"); if(inp.indexOf("HTTP/1.1")>0){ outputStream.writeBytes("HOST: " + server + "\r\n") ; outputStream.writeBytes("Connection: close\r\n\r\n") ; } else outputStream.writeBytes("\r\n") ; outputStream.flush() ; // outputStream.println(); //Send a command from keyboard to the server String line = null; //Declare a String to read lines into. while((line = inputStream.readLine()) != null) System.out.println(line); //Loop reading and displaying lines until null // is received. socket.close(); //Close the socket and keyboard input. } // end while((inp = ... disys.close() ; }//end try catch(UnknownHostException e){ System.out.println(e); System.out.println( "Must be online to run properly."); }//end catch UnknownHostException catch(IOException e){ // System.out.println(e); } }//end main }//end class NetSockets03