Exemplo n.º 1
0
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
        # send file