Skip to content

Commit 0207780

Browse files
authored
problematic line :)
getting rid of it
1 parent 5e80982 commit 0207780

File tree

1 file changed

+22
-29
lines changed

1 file changed

+22
-29
lines changed

ProjectA.py

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,30 @@ def handle_client(conn, addr):
2424
global message
2525

2626
print(f"[NEW CONNECTION] {addr} connected.")
27-
connected = True
28-
while connected:
29-
try:
30-
message = conn.recv(1024).decode()
31-
filename = message.split()[1]
32-
f = open(filename[1:], 'r')
33-
outputdata = f.read()
34-
# Send one HTTP header line into socket
35-
message = conn.recvfrom(1024).decode()
36-
conn.send("HTTP/1.1 200 OK\r\n\r\n".encode())
37-
conn.send("\r\n".encode())
38-
# Send the content of the requested file to the client
39-
for i in range(0, len(outputdata)):
40-
conn.send(outputdata[i].encode())
41-
conn.send("\r\n".encode())
42-
# Terminate connection
43-
conn.close()
44-
45-
except IOError:
46-
# Send response message for file not found
47-
conn.send("HTTP/1.1 404 Not Found\r\n\r\n".encode())
48-
conn.send("<html><head>404 Not Found</head><body></body></html>\r\n".encode())
49-
conn.close()
50-
51-
# Close client socket
52-
# Fill in start
27+
try:
28+
message = conn.recv(1024).decode()
29+
filename = message.split()[1]
30+
f = open(filename[1:], 'r')
31+
outputdata = f.read()
32+
33+
# Send one HTTP header line into socket
34+
conn.send("HTTP/1.1 200 OK\r\n\r\n".encode())
35+
conn.send("\r\n".encode())
36+
# Send the content of the requested file to the client
37+
for i in range(0, len(outputdata)):
38+
conn.send(outputdata[i].encode())
39+
conn.send("\r\n".encode())
40+
41+
except IOError:
42+
# Send response message for file not found
43+
conn.send("HTTP/1.1 404 Not Found\r\n\r\n".encode())
44+
conn.send("<html><title>404 Not Found</title><body><h1>404 Not Found</h1></body></html>\r\n".encode())
5345
conn.close()
54-
# Fill in end
55-
serverSocket.close()
46+
47+
# Close client socket
48+
conn.close()
5649

5750

5851
print("[STARTING] server is starting...")
5952
start()
60-
sys.exit() # Terminate the program after sending the corresponding data
53+
sys.exit() # Terminate the program

0 commit comments

Comments
 (0)