this is a TCP python socket server. this code have been used by so many people and someone asked me to make it unique, so what can i change to make it unique without breaking the code ? first file is server.py, and second one is client.py. import socket import sys import os from util import send_file, recv_file, send_listing, recv_listing script_dir = os.path.dirname(__file__) rel_path = "server/" abs_file_path = os.path.join(script_dir, rel_path) srv_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try:     srv_sock.bind(("0.0.0.0", int(sys.argv[1])))     srv_sock.listen(5) except Exception as e:     print(e)     exit(1) while True:     try:         print("Waiting for new client... ")         cli_sock, cli_addr = srv_sock.accept()         cli_addr_str = str(cli_addr)         print("Client " + cli_addr_str + " connected. Now chatting...")         commandList = cli_sock.recv(1024)         command = commandList.decode().split(" ", 1)         if (command[0] == "list"):             send_listing(cli_sock)         else:             textfileName = command[1]             fileName=abs_file_path+textfileName             if (command[0] == "put"):                 recv_file(fileName,cli_sock)             elif (command[0] == "get"):                 send_file(fileName,cli_sock)     finally:         cli_sock.close() exit(0)           import socket import sys import os from util import send_file, recv_file, send_listing, recv_listing script_dir = os.path.dirname(__file__) rel_path = "client/" abs_file_path = os.path.join(script_dir, rel_path) cli_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) srv_addr = (sys.argv[1], int(sys.argv[2])) try:     cli_sock.connect(srv_addr)     print("Connected. Now chatting...") except Exception as e:     print(e)     exit(1) try:     if(len(sys.argv)==4):         user_input = sys.argv[3]+" "     elif(len(sys.argv)==5):         user_input = sys.argv[3]+" "+sys.argv[4]     command = user_input.split(" ", 1)     if (command[0] == "list"):         cli_sock.sendall(str.encode(user_input))         li=recv_listing(cli_sock)         print(" ".join(li))     else:         filename = abs_file_path+command[1]         if (command[0] == "put"):             cli_sock.sendall(str.encode(user_input))             send_file(filename,cli_sock)         elif (command[0] == "get"):             cli_sock.sendall(str.encode(user_input))             recv_file(filename,cli_sock) finally:     cli_sock.close() exit(0)

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

this is a TCP python socket server.

this code have been used by so many people and someone asked me to make it unique, so what can i change to make it unique without breaking the code ? first file is server.py, and second one is client.py.

import socket
import sys
import os
from util import send_file, recv_file, send_listing, recv_listing

script_dir = os.path.dirname(__file__)
rel_path = "server/"
abs_file_path = os.path.join(script_dir, rel_path)

srv_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
    srv_sock.bind(("0.0.0.0", int(sys.argv[1])))
    srv_sock.listen(5)
except Exception as e:
    print(e)
    exit(1)

while True:
    try:
        print("Waiting for new client... ")
        cli_sock, cli_addr = srv_sock.accept()
        cli_addr_str = str(cli_addr)
        print("Client " + cli_addr_str + " connected. Now chatting...")


        commandList = cli_sock.recv(1024)
        command = commandList.decode().split(" ", 1)

        if (command[0] == "list"):
            send_listing(cli_sock)
        else:
            textfileName = command[1]
            fileName=abs_file_path+textfileName

            if (command[0] == "put"):
                recv_file(fileName,cli_sock)
            elif (command[0] == "get"):
                send_file(fileName,cli_sock)

    finally:
        cli_sock.close()
exit(0)
 
 
 
 
 
import socket
import sys
import os
from util import send_file, recv_file, send_listing, recv_listing

script_dir = os.path.dirname(__file__)
rel_path = "client/"
abs_file_path = os.path.join(script_dir, rel_path)

cli_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
srv_addr = (sys.argv[1], int(sys.argv[2]))
try:
    cli_sock.connect(srv_addr)

    print("Connected. Now chatting...")
except Exception as e:
    print(e)
    exit(1)


try:
    if(len(sys.argv)==4):
        user_input = sys.argv[3]+" "
    elif(len(sys.argv)==5):
        user_input = sys.argv[3]+" "+sys.argv[4]

    command = user_input.split(" ", 1)

    if (command[0] == "list"):
        cli_sock.sendall(str.encode(user_input))
        li=recv_listing(cli_sock)
        print(" ".join(li))
    else:
        filename = abs_file_path+command[1]
        if (command[0] == "put"):
            cli_sock.sendall(str.encode(user_input))
            send_file(filename,cli_sock)
        elif (command[0] == "get"):
            cli_sock.sendall(str.encode(user_input))
            recv_file(filename,cli_sock)

finally:
    cli_sock.close()

exit(0)
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Network Protocols
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY