Giter VIP home page Giter VIP logo

simplewebserver's Introduction

SimpleWebServer

V00796911 Lab Section: B01

Specification for this project:

How it works:

  1. check number of arguments when the program was invoked
  2. change current dir to the given dir
  3. open a socket
  4. setsocketopt()
  5. bind the socket
  6. use select() to check for input (keyboard or client)
  7. if input is from keyboard if input is 'q' then close the socket and exit otherwise do nothing
  8. if input is from client then break up the request by spaces using strtok() check if the http method, version, and end of http header is valid if not then 400 bad request if the request is valid then check if the file exist then read the whole file and send 200 OK and break the data into small size and send to the client otherwise 404 not found otherwise 400 bad request

Sample Client Request: echo -e -n "GET /index.html HTTP/1.0\r\n\r\n" | nc -u -s 192.168.1.100 10.10.1.100 8080

'/' is the directory given when the server is invoke Example: ./sws 8080 /tmp/www so '/' is /tmp/www

testfile.sh expect result

  1. HTTP/1.0 200 OK
  2. HTTP/1.0 200 OK
  3. HTTP/1.0 400 Bad Request
  4. HTTP/1.0 400 Bad Request
  5. HTTP/1.0 404 Not Found
  6. HTTP/1.0 404 Not Found
  7. HTTP/1.0 200 OK

simplewebserver's People

Contributors

mooktungs avatar

Watchers

 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.