Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from datetime import datetime
- import socket
- SERVER_IP = "localhost"
- SERVER_PORT = 420
- STOP_KEY = "8"
- BUFFER_SIZE = 1024
- def main():
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock.connect((SERVER_IP, SERVER_PORT)) # Connects to the server
- client_input = ""
- print('[' + datetime.now().strftime("%H:%M:%S") + "] [CONNECTED] " + SERVER_IP + ':' + str(SERVER_PORT) + '\n')
- print(sock.recv(BUFFER_SIZE).decode()) # Print welcome message
- while client_input != STOP_KEY:
- show_menu() # Shows the menu
- client_input = input("> ") # Get request
- try:
- sock.sendall(client_input.encode()) # Send request for the info
- print(sock.recv(BUFFER_SIZE).decode()) # Get the requested info
- except Exception as e:
- print("Error: ", e)
- sock.close()
- break
- # Stop key pressed
- sock.close()
- def show_menu():
- """
- Shows the menu
- """
- print("""
- - [MENU] Select by the digit [MENU] -
- 1. Get list of the albums
- 2. Get list of the songs in the album
- 3. Get length of song
- 4. Get LYRICS of song
- 5. Find in which album is the song
- 6. Search song by the name
- 7. Search song by the LYRICS
- 8. Quit (Close connection)
- - [MENU] Select by the digit [MENU] -
- """)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement