Below is cache.py. Make sure the code works properly and is plagarism free. Make sure to show the screenshot of the output with the screenshot of the code being tested as plagarism free. cache.py import socket import sys
Below is cache.py. Make sure the code works properly and is plagarism free. Make sure to show the screenshot of the output with the screenshot of the code being tested as plagarism free.
cache.py
import socket
import sys
def handle_client(client_socket):
while True:
command = client_socket.recv(1024).decode()
if not command:
break
if command == 'quit':
break
elif command == 'put':
receive_file(client_socket)
elif command == 'get':
send_file(client_socket)
else:
print("Invalid command.")
break
client_socket.close()
def receive_file(client_socket):
pass
def send_file(client_socket):
pass
def main():
if len(sys.argv) != 4:
print("Usage: cache.py <port> <server_ip> <server_port> <transport_protocol>")
return
port, server_ip, server_port, transport_protocol = int(sys.argv[1]), sys.argv[2], int(sys.argv[3]), sys.argv[4]
cache_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
cache_socket.bind(('0.0.0.0', port))
cache_socket.listen(5)
print(f"Cache listening on port {port}...")
while True:
client_socket, addr = cache_socket.accept()
print(f"Accepted connection from {addr[0]}:{addr[1]}")
handle_client(client_socket)
if __name__ == "__main__":
main()
Trending now
This is a popular solution!
Step by step
Solved in 3 steps