Untitled
unknown
plain_text
2 months ago
1.9 kB
4
Indexable
import socket import time HOST = '127.0.0.1' PORT = 12345 while True: try: # Create a socket and connect to the server client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client_socket.connect((HOST, PORT)) # Receive and display welcome message welcome_message = client_socket.recv(1024).decode() if "Shop is currently closed" in welcome_message: print("\nSERVER RESPONSE: ", welcome_message) print("Retrying in 3 seconds...\n") client_socket.close() time.sleep(3) # Wait before retrying continue # Retry connection print("\n" + welcome_message) # Send customer details name = input("Enter your Name: ").strip() client_socket.send(name.encode()) num_pizzas = input("Enter number of pizzas: ").strip() client_socket.send(num_pizzas.encode()) address = input("Enter your Address: ").strip() client_socket.send(address.encode()) phone = input("Enter your Phone Number: ").strip() client_socket.send(phone.encode()) # Display waiting message before receiving the response print("\nPlease wait for the Order Status...") # Wait for the server's decision (Approval/Rejection) server_response = client_socket.recv(1024).decode() print("\nSERVER RESPONSE: ", server_response) break # Exit loop after successful order except ConnectionResetError: print("Error: The server closed the connection unexpectedly. Retrying in 3 seconds...\n") time.sleep(3) # Wait before retrying except Exception as e: print(f"An error occurred: {e}") break # Exit loop on critical errors finally: client_socket.close()
Editor is loading...
Leave a Comment