... | ... | @@ -3,6 +3,7 @@ |
|
|
# Session 12: HTTP protocol
|
|
|
|
|
|
* **Time**: 2h
|
|
|
* **Date**: XXXX, XX-XX-2023
|
|
|
* **Goals**:
|
|
|
* Learn about the HTTP protocol
|
|
|
* Write our first web server using sockets
|
... | ... | @@ -155,7 +156,7 @@ We start from a **simple server** that just **receives a request message** and p |
|
|
|
|
|
**Create** the **S12 folder** and the **new** python file **echo-server.py**. Copy & paste the following code:
|
|
|
|
|
|
```python3
|
|
|
```python
|
|
|
import socket
|
|
|
import termcolor
|
|
|
|
... | ... | @@ -188,7 +189,7 @@ ls.bind((IP, PORT)) |
|
|
# -- Become a listening socket
|
|
|
ls.listen()
|
|
|
|
|
|
print("SEQ Server configured!")
|
|
|
print("Echo server configured!")
|
|
|
|
|
|
# --- MAIN LOOP
|
|
|
while True:
|
... | ... | @@ -196,7 +197,7 @@ while True: |
|
|
try:
|
|
|
(cs, client_ip_port) = ls.accept()
|
|
|
except KeyboardInterrupt:
|
|
|
print("Server Stopped!")
|
|
|
print("Server stopped!")
|
|
|
ls.close()
|
|
|
exit()
|
|
|
else:
|
... | ... | @@ -205,7 +206,7 @@ while True: |
|
|
process_client(cs)
|
|
|
|
|
|
# -- Close the socket
|
|
|
cs.close()
|
|
|
cs.close()
|
|
|
```
|
|
|
|
|
|
First, let's check that our server works as expected. From the **linux console**, let's send it a message the **echo** and **nc commands**:
|
... | ... | @@ -353,7 +354,7 @@ ls.bind((IP, PORT)) |
|
|
# -- Become a listening socket
|
|
|
ls.listen()
|
|
|
|
|
|
print("SEQ Server configured!")
|
|
|
print("Echo server configured!")
|
|
|
|
|
|
# --- MAIN LOOP
|
|
|
while True:
|
... | ... | @@ -361,7 +362,7 @@ while True: |
|
|
try:
|
|
|
(cs, client_ip_port) = ls.accept()
|
|
|
except KeyboardInterrupt:
|
|
|
print("Server Stopped!")
|
|
|
print("Server stopped!")
|
|
|
ls.close()
|
|
|
exit()
|
|
|
else:
|
... | ... | @@ -496,7 +497,7 @@ ls.bind((IP, PORT)) |
|
|
# -- Become a listening socket
|
|
|
ls.listen()
|
|
|
|
|
|
print("SEQ Server configured!")
|
|
|
print("Green server configured!")
|
|
|
|
|
|
# --- MAIN LOOP
|
|
|
while True:
|
... | ... | @@ -504,7 +505,7 @@ while True: |
|
|
try:
|
|
|
(cs, client_ip_port) = ls.accept()
|
|
|
except KeyboardInterrupt:
|
|
|
print("Server Stopped!")
|
|
|
print("Server stopped!")
|
|
|
ls.close()
|
|
|
exit()
|
|
|
else:
|
... | ... | @@ -568,7 +569,7 @@ All the exercises and experiments donde during this session should be stored in |
|
|
|
|
|
* **Filename**: S12/e1.txt
|
|
|
* **Description**: A text file to answer the following questions
|
|
|
*
|
|
|
|
|
|
Run the **webserver-2**. Open the browser and connect to the URL: [**http://127.0.0.1:8080/hello**](http://127.0.0.1:8080/hello)
|
|
|
|
|
|
* Which is the request line?
|
... | ... | |