sendall() :TCP recvfrom() :UDP recvfrom_into() :UDP sendto() :UDP ''' HOST = 'localhost' # HOST = '::1' PORT = 9999 ADDR = (HOST, PORT) if __name__ == "__main__": # s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) # s.settimeout(5) # s.connect(ADDR) # print(s.recv(1024).decode('utf-8')) # for data in [b'Tony', b'Nick', b'Ulysses']: # s.send(data) # print(s.recv(1024).decode('utf-8')) # s.send(b'exit') # s.close() s = MySocket() s.connect(HOST, PORT) print(s.myreceive(32).decode('utf-8')) for data in [b'Tony', b'Nick', b'Ulysses']: print(len(data)) s.mysend(data) print(s.myreceive(32).decode('utf-8')) s.mysend(b'exit') s.close()
elif state == "recieveFile": msg = input('\nWhich one do you want? ') socketClient.send(msg.encode()) print('\nWaiting for file...') file_name = "temp_file" if dFiles: file_name = dFiles[int(msg)] dFile = socketClient.recieveArquive(file_name) print('Received file, saved as', file_name) state = "menu" elif state == "break": break elif state== "closeConnection": socketClient.close() state = "break" # while True: # menu_server = socket_client.recv(SIZE) # não sabia qual parametro colocar # menu_server = menu_server.decode() # turn bytes into str # print(menu_server) # choice = str(input('\nSua escolha:\n')) # socket_client.send(choice.encode()) # if choice == '1': # asks to list files # d_files = socket_client.recv(SIZE*30) # receive files' list from server | ajeitar tamanho!!