Question
https://www.chegg.com/homework-help/questions-and-answers/pleas-give-server-client-code-pleas-dont-copy-others-sorry-bother-q107084158?new=true in this question i don't think the server code is completed pleas complete the server code and check if the client and servers codes
https://www.chegg.com/homework-help/questions-and-answers/pleas-give-server-client-code-pleas-dont-copy-others-sorry-bother-q107084158?new=true
in this question i don't think the server code is completed pleas complete the server code and check if the client and servers codes work good or not
please i dont have time
here is the pic of the question
this is the server code where is not finished
import json import requests import socket import threading
# API key for aviationstack.com API_KEY = "your_api_key"
# Airport code entered by the user arr_icao = input("Enter airport code: ")
# Function to retrieve data for the specified airport from the API def get_airport_data(arr_icao): # Construct the API request URL url = f"http://api.aviationstack.com/v1/flights?access_key={API_KEY}&arr_icao={arr_icao}&limit=100" # Send the request and retrieve the response data response = requests.get(url) data = response.json() # Return the data return data
# Class for a thread to handle a client's requests class ClientThread(threading.Thread): def _init_(self, client_name, client_sock): threading.Thread._init_(self) self.client_name = client_name self.client_sock = client_sock # Method to handle the client's requests def run(self): while True: # Wait for a request from the client request = self.client_sock.recv(1024).decode() # Split the request into type and parameters request_type, *request_params = request.split() # Handle the request based on its type if request_type == "arrived_flights": # Search the data for arrived flights arrived_flights = [f for f in data if f["flight"]["status"] == "arrived"] # Send a response with the flight number, estimated time of arrival, and terminal number for each matching flight response = " ".join([f"{f['flight']['flight_number']} {f['flight']['arrival']['estimated_time']} {f['flight']['arrival']['terminal']}" for f in arrived_flights]) elif request_type == "delayed_flights": # Search the data for delayed flights delayed_flights = [f for f in data if f["flight"]["status"] == "delayed"] # Send a response with the flight number, original time, and estimated time of arrival for each matching flight response = " ".join([f"{f['flight']['flight_number']} {f['flight']['departure']['scheduled_time']} {f['flight']['arrival']['estimated_time']}" for f in delayed_flights]) elif request_type == "flights_from_city": city =
here is the client code
import socket
# Server address and port SERVER_ADDRESS = ("localhost", 8000)
# Function to send a request to the server and receive the response def send_request(request): # Create a client socket client_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Connect to the server client_sock.connect(SERVER_ADDRESS) # Send the request to the server client_sock.send(request.encode()) # Receive the response from the server response = client_sock.recv(1024).decode() # Close the socket client_sock.close() # Return the response return response
# Function to display the options for the different request types and allow the user to input the necessary parameters def get_request_input(): # Display the options for the different request types print("1. Arrived flights") print("2. Delayed flights") print("3. All flights coming from a specific city") print("4. Details of a particular flight") # Prompt the user to choose a request type choice = input("Enter your choice: ") # Return the request type and any necessary parameters based on the user's choice if choice == "1": return "arrived_flights" elif choice == "2": return "delayed_flights" elif choice == "3": city = input("Enter the city: ") return f"flights_from_city {city}" elif choice == "4": flight_number = input("Enter the flight number: ") return f"flight_details {flight_number}"
Assignment In this project, the learners should create a client-server system that exchanges information about flights at a certain airport. The emphasis in this project is on client/server architecture, network communication, multithreading, API, and applying good coding practices. The system should consist of two Python scripts (the server and the client). The server should retrieve data of a selected airport from aviationstack.com via a proper API, extract the required information from the retrieved data, manage connections with multiple clients at the same time, and respond to client requests. The Server Script The server should retrieve the information about flights at a specific airport over an API and handle the clients with their requests. It should extract the needed information from the API response and send it to the client. The server should conduct the following tasks: 1. Once the server starts up, it should ask the user to enter the airport code (arr_icao). 2. Uses the proper API to retrieve 100 records of flights at the specified airport (use avaitionstack.com). 3. Store the retrieved data in a JSON file called "group_ID.json" (for testing and evaluation purposes) 4. Wait for clients' requests to connect (should accept at least three connections simultaneously). a. Accept the connection. b. Store the client's name and display it on the terminal. 5. Wait for clients' requests, search the retrieved data for matching, and send a reply with the matching information. a. All arrived flights (return flight no., estimated time of arrival, and terminal number). b. All delayed flights (return flight no., original time, and estimated time of arrival). c. All flights from a specific city (return flight no., original time, and status). d. Details of a particular flight (return flight no., original time, estimated time, status, and terminal number). The server should display the following details clearly on its screen: 1. The acceptance of a new connection with the client's name. 2. The requester name, type of request, and request parameters. 3. The disconnection of a client with its name. The Client Script The client script should connect to the server, send different types of requests, and receive and display the responses. The client should be user-friendly and display the options and results neatly. The client should stay connected and ready to send new requests until the user chooses to quit. The client program should conduct the following tasks: 1. Establish a connection with the server and send a username to identify itself. 2. Sends one of the following four request types: a. Arrived flights: the client should display the flight code (IATA), departure airport, arrival time, terminal, and gate. 2 b. Delayed flights: the client should display the flight code (IATA), departure airport, departure time, estimated arrival time, terminal, and gate. c. All flights coming from a specific city: (the client should display flight code (IATA), departure airport, departure time, estimated arrival time, terminal, and gate. d. Details of a particular flight: the client should display flight code (IATA), date, departure (airport, gate, and terminal), arrival (airport, gate, terminal), status, scheduled departure time, scheduled arrival time, estimated arrival time, and delay. 3. Close the connection and leave when the user selects the Quit option. Note: the retrieved information should be displayed clearly and neatlyStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started