Below is server.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. server.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) != 3: print("Usage: server.py ") return try: port, transport_protocol = int(sys.argv[1]), sys.argv[2] except ValueError: print("Invalid port number.") return server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_socket.bind(('0.0.0.0', port)) server_socket.listen(5) print(f"Server listening on port {port}...") while True: client_socket, addr = server_socket.accept() print(f"Accepted connection from {addr[0]}:{addr[1]}") handle_client(client_socket) if __name__ == "__main__": main()
Below is server.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.
server.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) != 3:
print("Usage: server.py <port> <transport_protocol>")
return
try:
port, transport_protocol = int(sys.argv[1]), sys.argv[2]
except ValueError:
print("Invalid port number.")
return
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind(('0.0.0.0', port))
server_socket.listen(5)
print(f"Server listening on port {port}...")
while True:
client_socket, addr = server_socket.accept()
print(f"Accepted connection from {addr[0]}:{addr[1]}")
handle_client(client_socket)
if __name__ == "__main__":
main()
Step by step
Solved in 4 steps with 2 images