netcat-web-server/README.md
2024-12-06 22:14:39 -05:00

57 lines
1.0 KiB
Markdown

# netcat Web Server
Serve a web page and inspect HTTP requests using `netcat`.
## Usage
1. After cloning the repository, make sure that the `ncws.h` script is executable.
````sh
$ chmod +x ncws.h
````
3. Run the `ncws.h` script.
````sh
$ ./ncws.h
netcat web server
Listening on 0.0.0.0 8080
````
4. In another terminal, make a request to the server using `curl`.
````sh
$ curl http://127.0.0.1:8080
````
5. `netcat` will print the request and send a response.
````sh
...
Connection received on localhost 40790
GET / HTTP/1.1
Host: 127.0.0.1:8080
User-Agent: curl/8.11.0
Accept: */*
````
6. `curl` should receive the response and print it.
````sh
$ curl http://127.0.0.1:8080
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello, World!</title>
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>
````
7. The script will then resume listening for more requests.
````sh
...
Listening on 0.0.0.0 8080
````
8. Press `CTRL-C` to terminate the script.