Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Finally I was able to do it. The problem was with the socket.recv(). I was asking for the application to execute several lines, but nothing arrived from the server.The client never executed the lines below that one, because it was expecting data to keep on running the next lines. I rearranged the code to deal with this, and it's working great. Definitely love Python :)</p> <p>Server side:</p> <pre><code>import os import socket PORT = 8080 HOST = 'localhost' socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) socket.bind((HOST,PORT)) socket.listen(1) conn, addr = socket.accept() print '\033[46m\033[34m\033[1mBienvenido al File Sender v.0.02 hecho en Python. Este programa permite enviar archivos a traves de tu maquina\033[0m' ANSI_RED = '\033[31m' ANSI_BLUE = '\033[34m' ESCAPEANSI = '\033[0m' def seleccion_path(): PATH = raw_input('\033[34m\033[1mSelect the Path (./ by default)').strip('n') if PATH == '': PATH = os.getcwd() print PATH, ESCAPEANSI acepta_path = raw_input('\033[34m\033[1mSi o No (S/N)').lower().strip(' ') if acepta_path == 's' or acepta_path == 'si': return PATH else: seleccion_path() def filesDir(path): files = os.listdir(PATH) for fl in files: i = int(files.index(fl))+1 print ANSI_RED + str(i)+ ')' + fl return files PATH = seleccion_path() print 'el PATH seleccionado es:', PATH + '\n' filesDir(PATH) fileSelected = int(raw_input(ANSI_BLUE + 'Select a file with the number').strip(' ').lower()) print PATH + filesDir(PATH)[fileSelected-1] filepath = PATH + filesDir(PATH)[fileSelected-1] #envia nombre del file conn.send(filepath) qLines = len(open(PATH + filesDir(PATH)[fileSelected-1], 'rb').readlines()) fileToSend = open(filepath, 'rb') while True: data = fileToSend.readline() if data: conn.send(data) else: break fileToSend.close() conn.sendall('') conn.close() print '\033[43m File sent' #Finaliza el programa y deja los codigos ANSI cerrados print ESCAPEANSI exit() </code></pre> <p>Client side:</p> <pre><code>import os import socket PORT = 8080 HOST = 'localhost' nombrearchivo = raw_input('define a name with its extension').strip(' ') socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) socket.connect((HOST, PORT)) filename = socket.recv(1024) fname = open('./'+nombrearchivo, 'wb') while True: strng = socket.recv(1024) if strng: print strng fname.write(strng) else: fname.close() break socket.close() print 'Data received correctly' exit() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload