Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6812057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:24:11+00:00 2026-05-26T20:24:11+00:00

I’m trying to make a simple http client server using java. It will show

  • 0

I’m trying to make a simple http client server using java. It will show the client’s request as well as the server’s response. For example server will send back

   HTTP/1.0 200 OK
   Connection: Close. etc.

Previously i had a echo client server. Now I’ve turned my echo server to act as a http server. I’ve tried Goggling about how to implement the head and get with the client but i noticed usually all of the example used apache framework. Is there a way to implement these method without apache framework.
My echo client which i’m trying to convert into a http client:

       import java.io.*;
       import java.net.*;

          public class Ec1
      {
      public static void main(String[] args)
        {
           try
        {
          Socket s = new Socket("127.0.0.1", 80);
        BufferedReader r = new BufferedReader(new                                 InputStreamReader(s.getInputStream()));
            PrintWriter w = new PrintWriter(s.getOutputStream(), true);
           BufferedReader con = new BufferedReader(new InputStreamReader(System.in));
          String line;
           do
        {
         line = r.readLine();
          if ( line != null )
        System.out.println(line);
       line = con.readLine();
          w.println(line);
        }
         while ( !line.trim().equals("bye") );
          }
          catch (Exception err)
        {
         System.err.println(err);
        }
        }
     }

My Http server:

          import java.io.BufferedReader;
          import java.io.InputStreamReader;
          import java.io.PrintWriter;
          import java.net.ServerSocket;
          import java.net.Socket;

          public class Echo
                 { 

 protected void start() {
        ServerSocket s;

        System.out.println("Webserver starting up on port 80");

        try {
          // create the main server socket
          s = new ServerSocket(80);
        } catch (Exception e) {
          System.out.println("Error: " + e);
          return;
        }
        Socket clientSocket = null; 
        System.out.println ("Waiting for connection.....");
        try { 
             clientSocket = s.accept(); 
             System.out.println("Connection, sending data.");
             BufferedReader in = new BufferedReader(new InputStreamReader(
                     clientSocket.getInputStream()));
             PrintWriter out = new PrintWriter(clientSocket.getOutputStream());


             String str = ".";
             while (!str.equals(""))
               str = in.readLine();


             out.println("HTTP/1.0 200 OK");
             out.println("Content-Type: text/html");
             out.println("Server: Bot");

             out.println("");

             out.println("<H1>Welcome to the Ultra Mini-WebServer</H2>");
             out.flush();
             clientSocket.close();
             s.close(); 
           } catch (Exception e) {
             System.out.println("Error: " + e);
           }
         }

        public static void main(String args[]) {
            WebServer ws = new WebServer();
            ws.start();
                    }
           }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:24:12+00:00Added an answer on May 26, 2026 at 8:24 pm

    Yes, there is, just interpret your request you’re getting from the client.

    From the following code (in HttpServer), parse:

    String str = ".";
    while (!str.equals("")) {
      str = in.readLine();
    
      if (str.startsWith("HEAD")) {
          //Head execution here...
      }
    }
    

    Etc…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.