尝试将messege传递给客户端时出错

时间:2017-11-28 19:40:51

标签: python

先生,我正在使用python开发服务器客户端应用程序。但当我运行服务器它只是工作正常,当我运行客户端,在服务器中我收到一个错误说

    conn.sendall(回复) TypeError:需要类似字节的对象,而不是' tuple'

似乎服务器无法将messege回复给客户端。但我不知道如何解决它。请有人帮帮我......这是我的服务器代码:

import socket
import sys

HOST = '127.0.0.1';   # Symbolic name meaning all available interfaces
PORT = 2014; # Arbitrary non-privileged port

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print ("Socket created")
print ("Socket bind complete")
s.bind((HOST, PORT))
s.listen(10) 
print ("Socket now listening")

#now keep talking with the client
while True:
#wait to accept a connection - blocking call
conn, addr = s.accept()
print ("Connected with ", addr[0] ,":" , str(addr[1]))

data = conn.recv(1024)
reply = ("O", data)
if not data: 
    break

conn.sendall(reply)// here it comes the error, i have used encode.('utf-8') but no luck

conn.close()
s.close()

0 个答案:

没有答案