为什么返回一个完全空的值?

时间:2018-09-23 18:24:37

标签: python python-3.x

服务器:

PyErr_Restore

客户:

import socket

HOST = ''
PORT = 9876
ADDR = ("127.0.0.1",4444)
BUFSIZE = 4096

serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

serv.bind(ADDR)
serv.listen(5)

print('listening ...')
conn, addr = serv.accept()
print('client connected ... ', addr)

def download():
  while True:
    print("Got succesfully to the function")
    data = conn.recv(BUFSIZE)
    print(data)
    if not data: break
    myfile = open(command[1], 'wb')
    myfile.write(data)
    print ('writing file ....')
    myfile.close()
    print ('finished writing file')



while True:
  command = input(">> ") #Basicamente lo que esta pasando aqui:
  command = command.encode() #Se encodea para mandarlo
  conn.send(command) #Se manda bien
  command = command.decode() #Se desencodea
  command = command.split(" ") #Y se hace en una lista para los "ifs"
  data = conn.recv(BUFSIZE)
  print("Recieved package")
  if command[0] == "download":
    download()
  else:
    print(data)

conn.close()
print ('client disconnected')

在进入

之前,一切似乎都还不错。
import socket



HOST = 'localhost'
PORT = 9876
ADDR = ("127.0.0.1",4444)
BUFSIZE = 4096
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(ADDR)

recibio = client.recv(BUFSIZE).decode()
recibio = recibio.split(" ")


def mandar_archivo():   
    bytes = open(recibio[1], 'rb').read()
    print(recibio[1])
    print(len(bytes))
    client.sendall(bytes)

mandar_archivo()
client.close()

部分客户。我说这是因为,当我尝试打印字节值时,我得到的是空值。如果我在服务器上打印数据,也会发生同样的事情。我还检查了bytes = open(recibio[1], 'rb').read() 的值,它很好,与我在服务器端发送的值相同。

是什么原因造成的?

0 个答案:

没有答案