列表列表可以作为字节从python发送吗?

时间:2020-04-29 16:14:25

标签: python sockets client-server

我有一个列表列表,希望将其从python服务器发送到c#客户端。

格式看起来像这样first 4 values representing integers converted to bytes while the rest represent png images

这是代码:

s = socket.socket()
socket.setdefaulttimeout(None)
print('socket created ')
port = 60000
s.bind(('127.0.0.1', port)) #local host
s.listen(30) #listening for connection for 30 sec?
print('socket listensing ... ')
while True:
    try:
        c, addr = s.accept() #when port connected
        bytes_received = c.recv(4000) #received bytes
        array_received = np.frombuffer(bytes_received, dtype=np.float32) 
        print(array_received)

        nn_output = return_prediction()  
        c.sendall(nn_output) #sending back
        c.close()
    except Exception as e:
        logging.error(traceback.format_exc())
        print("error")
        c.sendall(bytearray([]))
        c.close()
        break

错误:TypeError:需要一个类似字节的对象,而不是“列表”

是否有可能使其正常工作?

0 个答案:

没有答案