Languages
[Edit]
EN

Java - simple single client Fake-HTTP server example (socket server)

10 points
Created by:
evangeline
420

In this short article, we would like to show how using sockets, write a simple single client Fake-HTTP server in Java.

The solution in the article runs a simple Fake-HTTP server that is able to get only one client connection at the same time. The server listens on port 80. Client requests are only printed in the server console, sending back always the same simple web page - this is the reason why we called it Fake-HTTP server.

Server usage steps:

  1. run Fake-HTTP server (the below Java program),
  2. open http://localhost address in the web browser,

    The web browser should send some similar text to the server as request:

    Where:
    - each line should be separated with \r\n,
    - last empty line means request end.
  3. as response in the web browser we should see:

    The server sends text as a response (it is interpreted by the web browser and displayed as a web page):

    Where each line should be separated by:
    \r\n in the header area,
    \n in the content area (it is recommended).

 

Used source code

Edit

Program.java file:

Example output:

 

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join