DNS_PORT = 49152 # o numero de porta pode ser entre 49152 e 65535 self_HOST = '' self_PORT = 50000 SIZE = 1024 # ver isso!! # send IP and domain to DNS with MySocket(socket.AF_INET, socket.SOCK_DGRAM) as s: s.dnsRegisterDomain("bois.com", DNS_HOST, DNS_PORT) data = s.recv(1024) print('Received', data.decode()) # wait for clients server_socket = MySocket(socket.AF_INET, socket.SOCK_STREAM) server_socket.bind((self_HOST, self_PORT)) server_socket.listen(1) conn, addr = server_socket.accept() print('\nConnected to:', addr) while True: files = listdir('../arquivos') client_choice = conn.recv(SIZE) # nao sabia qual parametro colocar client_choice = client_choice.decode() if client_choice == '1': # list files # list all files at the folder 'arquivos' d_files = pickle.dumps(files) # serialize files conn.sendall(d_files) # send files' list to client elif client_choice == '2': # send file
client_sockets = {} state = "listen" # # # # # MAIN # # # # # # send IP and domain to DNS with MySocket(AF_INET, SOCK_DGRAM) as dns_socket: dns_socket.dnsRegisterDomain("bois.com", DNS_HOST, DNS_PORT) data = dns_socket.recv(MESSAGE_SIZE) print('Received', data.decode()) print() dns_socket.close() # connect to client s = MySocket(AF_INET, SOCK_DGRAM) s.bind((SELF_HOST, SELF_PORT)) # while True: # if state == "listen": # # wait for connection request # segment, client_addr = s.receive_segment() # if segment.syn == '1': # # create new socket # tube_socket_port = SELF_PORT+1 # make port number random and check if it already exists # tube_socket = MySocket(AF_INET, SOCK_DGRAM) # tube_socket.bind((SELF_HOST, tube_socket_port)) # # # send ACK with socket port number # # syn_ack_data = str(tube_socket_port) # # syn_ack = Segment(next_seq, rcv_base, syn='1', data=syn_ack_data)