Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Client/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import socket

url = b"http://localhost:8080/hi/"

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:

s.connect(("localhost:8080", 80))

s.send(url)
resp = s.recv(4096)
ip = s.recv(4096)

print(resp.decode("utf-8"))
print(ip)
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Exp3BasicHttp
For Labo of Basic HTTP for Exp3 of Univ

## Mission

1. show Server Directory README.md
2. show Client Directory README.md
2. show Curl.md

## Setup

1. access 'https://github.com/Hardw01f/Exp3BasicHttp'
Expand Down
15 changes: 15 additions & 0 deletions Server/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
# Please write code of simple HTTP(Web) server

write this directory

## Specification

- write by using favorit language

- listen the API '/hi'
- return your IP address in Response Body
- return 'Hello: BasicHTTP!' Header in Response Header

## Response Exsample

```
HTTP/1.1 200 OK
Hello: BasicHTTP!
Date: Tue, 26 May 2020 06:53:14 GMT
Content-Length: 13
Content-Type: text/plain; charset=utf-8

10.10.11.194

```
30 changes: 30 additions & 0 deletions Server/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import socket
import datetime

dt = datetime.datetime.now()

host = socket.gethostname()
ip = socket.gethostbyname(host)
print(ip)
url = b"http://localhost:8080/hi/"

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((host, 80))
s.listen(1)

while True:
conn, addr = s.accept()
with conn:
while True:
data = conn.recv(1024)
print(data)

if data == url:
print('data : {}, addr: {}'.format(data, addr))
#conn.sendall(b'Received: ' + data)
conn.send(bytes("HTTP/1.1 200 OK\n" + "Hello: BasicHTTP!\n"
+ "Date: Tue, 26 May 2020 06:53:14 GMT\n"
+ "Content-Length: 13\n" + "Content-Type: text/plain;", "utf-8\n" + "\n"))

conn.send(bytes(ip,"utf-8"))
break
29 changes: 29 additions & 0 deletions response.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#awsのec2にserver.pyを置いて, localとremoteで試したやり方
e185729% python client.py [~]
HTTP/1.1 200 OK
Hello: BasicHTTP!
Date: Tue, 26 May 2020 06:53:14 GMT
Content-Length: 13
Content-Type: text/plain;
b'10.10.30.181'
e185729%

#curlコマンドを叩いて行ったやり方
e185729% curl -v http://54.92.28.20/hi/ [~]
* Trying 54.92.28.20...
* TCP_NODELAY set
* Connected to 54.92.28.20 (54.92.28.20) port 80 (#0)
> GET /hi/ HTTP/1.1
> Host: 54.92.28.20
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Hello: BasicHTTP!
< Date: Tue, 26 May 2020 06:53:14 GMT
< Content-Length: 13
* transfer closed with 13 bytes remaining to read
* stopped the pause stream!
* Closing connection 0
curl: (18) transfer closed with 13 bytes remaining to read