import socket def authenticate_user(tcp_socket):    while True:        response = tcp_socket.recv(1024).decode()        print(response)        username = input()        tcp_socket.sendall(username.encode())        response = tcp_socket.recv(1024).decode()        print(response)        password = input()        tcp_socket.sendall(password.encode())        auth_response = tcp_socket.recv(1024).decode()        if "successful" in auth_response:            print(auth_response)            return True        else:            print(auth_response) def receive_items(tcp_socket):    while True:        response = tcp_socket.recv(1024).decode()        if "Item List:" in response:            print(response)            while True:                item = tcp_socket.recv(1024).decode()                if not item.strip():                    break                print(item)            break def select_items(tcp_socket):    selected_items = []    while True:        item_id = input("Select item by entering its ID (0 to finish): ")        tcp_socket.sendall(item_id.encode())        if item_id == '0':            break        response = tcp_socket.recv(1024).decode()        if "Invalid item ID" in response:            print(response)        else:            selected_items.append(item_id)    return selected_items def receive_receipt(tcp_socket):    receipt = tcp_socket.recv(1024).decode()    print(receipt) def send_credit_card_details(tcp_socket):    credit_card_details = input("Enter encrypted credit card details: ")    tcp_socket.sendall(credit_card_details.encode())    print("Credit card details sent.") def main():    # Setup TCP client    tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)    server1_address = ('localhost', 5000)  # Server1's address     try:        tcp_socket.connect(server1_address)        print("Connected to Server1.")         # User Authentication        if authenticate_user(tcp_socket):            # Item Listing            receive_items(tcp_socket)             # Select Items            selected_items = select_items(tcp_socket)             # Receipt Generation            receive_receipt(tcp_socket)             # Credit Card Transaction            send_credit_card_details(tcp_socket)     finally:        tcp_socket.close() if __name__ == "__main__":    main()   This is my client program and it does not let me enter Item number to select after shoing Items list. Example Scenario: Client connects to server1 using TCP Server1 prompts for credentials and validates  Upon successful authentication, server1 provides item listing to the client. Client selects items. Server1 generates a receipt and returns it to the client. Client sends encrypted credit card details to server1. Server1 forwards the encrypted details to server2 using UDP. Server2 validates the credit card information and notifies server1. Server1 confirms payment to the client.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

import socket

def authenticate_user(tcp_socket):
    while True:
        response = tcp_socket.recv(1024).decode()
        print(response)
        username = input()
        tcp_socket.sendall(username.encode())
        response = tcp_socket.recv(1024).decode()
        print(response)
        password = input()
        tcp_socket.sendall(password.encode())
        auth_response = tcp_socket.recv(1024).decode()
        if "successful" in auth_response:
            print(auth_response)
            return True
        else:
            print(auth_response)

def receive_items(tcp_socket):
    while True:
        response = tcp_socket.recv(1024).decode()
        if "Item List:" in response:
            print(response)
            while True:
                item = tcp_socket.recv(1024).decode()
                if not item.strip():
                    break
                print(item)
            break

def select_items(tcp_socket):
    selected_items = []
    while True:
        item_id = input("Select item by entering its ID (0 to finish): ")
        tcp_socket.sendall(item_id.encode())
        if item_id == '0':
            break
        response = tcp_socket.recv(1024).decode()
        if "Invalid item ID" in response:
            print(response)
        else:
            selected_items.append(item_id)
    return selected_items

def receive_receipt(tcp_socket):
    receipt = tcp_socket.recv(1024).decode()
    print(receipt)

def send_credit_card_details(tcp_socket):
    credit_card_details = input("Enter encrypted credit card details: ")
    tcp_socket.sendall(credit_card_details.encode())
    print("Credit card details sent.")

def main():
    # Setup TCP client
    tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server1_address = ('localhost', 5000)  # Server1's address

    try:
        tcp_socket.connect(server1_address)
        print("Connected to Server1.")

        # User Authentication
        if authenticate_user(tcp_socket):
            # Item Listing
            receive_items(tcp_socket)

            # Select Items
            selected_items = select_items(tcp_socket)

            # Receipt Generation
            receive_receipt(tcp_socket)

            # Credit Card Transaction
            send_credit_card_details(tcp_socket)

    finally:
        tcp_socket.close()

if __name__ == "__main__":
    main()

 

This is my client program and it does not let me enter Item number to select after shoing Items list.

Example Scenario:

  1. Client connects to server1 using TCP
  2. Server1 prompts for credentials and validates 
  3. Upon successful authentication, server1 provides item listing to the client.
  4. Client selects items.
  5. Server1 generates a receipt and returns it to the client.
  6. Client sends encrypted credit card details to server1.
  7. Server1 forwards the encrypted details to server2 using UDP.
  8. Server2 validates the credit card information and notifies server1.
  9. Server1 confirms payment to the client.
AI-Generated Solution
AI-generated content may present inaccurate or offensive content that does not represent bartleby’s views.
steps

Unlock instant AI solutions

Tap the button
to generate a solution

Knowledge Booster
Types of Protocols
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education