Giter Club home page Giter Club logo

http-client-and-server's Introduction

HTTP-Client-and-Server

simple implemention of HTTP client and HTTP server using Java.
client has two methods of HTTP: GET and PUT.
server is able to handle both HTTP commands for GET and PUT.


Steps:

HTTPServer:

Compile: Javac HTTPServer.java

Run: Java HTTPSerer port#

HTTPClient:

Compile: Javac HTTPClient.java

Run: Java HTTPClient localhost:port#/path

Or

Run: Java HTTPClient PUT localhost:port#/path

Examples


Example1:

HTTPServer:

Zuns-MacBook-Pro:Zun_Lin zunlin$ javac HTTPServer.java
Zuns-MacBook-Pro:Zun_Lin zunlin$ java HTTPServer 10000
Listening on port 10000...
Client Made Connection
GET /index.html HTTP/1.0
Host: localhost
Time: Wed Apr 10 20:04:07 EDT 2019
User-Agent: VCU-CMSC491
User-name: Zun

HTTPClient:

HTTPClient.java HTTPServer.java
Zuns-MacBook-Pro:Zun_Lin zunlin$ javac HTTPClient.java
Zuns-MacBook-Pro:Zun_Lin zunlin$ java HTTPClient localhost:10000/index.html
HTTP/1.0 200 OK
Time: Wed Apr 10 20:04:07 EDT 2019
Last Modified: Wed Apr 10 20:03:02 EDT 2019


Example2(from browser):

HTTPServer:

GET / HTTP/1.1
Host: localhost:10000
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3 Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7,zh-TW;q=0.6
Cookie: io=-cZEFleqDL83mPMjAAAV

Client:

Google chrome


Example3(PUT):

HTTPServer:

PUT /index.html HTTP/1.0
Host: localhost
Time: Wed Apr 10 20:11:14 EDT 2019
User-Agent: VCU-CMSC491
User-name: Zun

HTTPClient:

Zuns-MacBook-Pro:Zun_Lin zunlin$ java HTTPClient PUT localhost:10000/index.html
606 FAILED File NOT Created
Time: Wed Apr 10 20:11:14 EDT 2019


Example4(PUT):

HTTPServer:
Client Made Connection
PUT /myApp/vcu.html HTTP/1.0
Host: localhost
Time: Wed Apr 10 20:15:03 EDT 2019
User-Agent: VCU-CMSC491

HTTPClient:

Zuns-MacBook-Pro:Zun_Lin zunlin$ java HTTPClient PUT localhost:10000/myApp/vcu.html
200 OK File Created
Time: Wed Apr 10 20:15:03 EDT 2019
PUT /myApp/vcu.html
Last Modified: Wed Apr 10 20:15:03 EDT 2019

http-client-and-server's People

Contributors

moonlight2521 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.