# 发送TCP数据 send()的返回值是发送的字节数量,
#这个数量值可能小于要发送的string的字节数,
# 也就是说可能无法发送string中所有的数据。如果有错误则会抛出异常。
s.send()
# 发送TCP数据,sendall()尝试发送string的所有数据,成功则返回None,失败则抛出异常。
s.sendall()
sock.sendall('Hello world\n') # 一次性全发过去
buffer = 'Hello world\n'
while buffer:
bytes = sock.send(buffer)
buffer = buffer[bytes:]
s.setblocking() # 设置套接字的(True)阻塞与(False)非阻塞模式