-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
33 lines (22 loc) · 901 Bytes
/
Copy pathclient.py
File metadata and controls
33 lines (22 loc) · 901 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import socket
HOST, PORT = "Host IPv4", 8888 # IPv4 address of the computer hosting the server.py file goes here.
def pttpGET(domain, page=None):
if page:
request = f"GET {domain}/{page}\n"
else:
request = f"GET {domain}\n" # Request list of pages if no specific page
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
client_socket.connect((HOST, PORT))
client_socket.sendall(request.encode("utf-8"))
response = ""
while True:
chunk = client_socket.recv(4096).decode("utf-8")
if not chunk:
break
response += chunk
return response
except ConnectionRefusedError:
print("Error: Could not connect to the PTTP server.")
finally:
client_socket.close()