def read_string(conn):
""" reads length of text to read, and then the text encoded in UTF-8, and returns the string"""
strlen = read_int(conn)
if not strlen:
return ''
res = to_bytes('')
while len(res) < strlen:
res = res + conn.recv(strlen - len(res))
res = utf_8.decode(res)[0]
if sys.version_info[0] == 2 and sys.platform != 'cli':
# Py 2.x, we want an ASCII string if possible
try:
res = ascii.Codec.encode(res)[0]
except UnicodeEncodeError:
pass
return res
评论列表
文章目录